public String[] split(String regex) Splits this string around matches of the given regular expression. This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array. The string "boo:and:foo", for example, yields the following results with these expressions: Regex Result : { "boo", "and", "foo" } o { "b", "", ":and:f" } Parameters: regex - the delimiting regular expression Returns: the array of strings computed by splitting this string around matches of the given regular expression Throws: PatternSyntaxException - if the regular expression's syntax is invalid
Splits this string around matches of the given regular expression.
This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array. The string "boo:and:foo", for example, yields the following results with these expressions: Regex Result
: { "boo", "and", "foo" }
o { "b", "", ":and:f" }
Parameters:
regex - the delimiting regular expression
Returns:
the array of strings computed by splitting this string around matches of the given regular expression
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
while(st.hasMoreTokens()){
System.out.println(st.nextToken());
}
就用这个!
就可以了
很实用的!
不过你在用这个方法的时候记得import java.util.StringTokenizer;
要是没有这个import的话,你的程序会出错的!
要求你以$为分隔符,遇到一个,就忽略它,继续输出下面的字符串,要是遇到2个连续的$$,就输出一个空格!楼主可以考虑考虑
你可以把你哪个帖子里的重要的帖出来看看么
import java.util.StringTokenizer;
public class split{
public static void main(String[] args)
{
String a = "good| |and|ss|xx";
StringTokenizer st=new StringTokenizer(a,"|");
while(st.hasMoreTokens()){
System.out.println(st.nextToken());
} }
}
有没有人能给出用SPLIT方法分割的代码 谢谢
public class split{
public static void main(String[] args)
{
String a = "good| |and|ss|xx";
String []result=a.split("[\\|]");
for(int i=;i<result.length();i++)
System.out.println(result[i]);
}
}
split里面是一个正则表达式,因为|是特殊符号,需要转义
public static void main(String[] args)
{
String a = "good| |and|ss|xx";
String []result=a.split("[\\|]");
for(int i=;i<result.length();i++)
System.out.println(result[i]);
}
}