Public string[] Split (String regex) default limit is 0
Public string[] Split (String regex, int limit)
When Limit>0, the n-1 time is applied
public static void Main (string[] args) {
String s = "Boo:and:foo";
string[] str = s.split (":", 2);
System.out.print (Str[0] + "," + str[1]);
}
Results:
Boo,and:foo
When limit<0, unlimited times are applied
public static void Main (string[] args) {
String s = "Boo:and:foo";
string[] str = s.split (":", -2);
for (int i = 0; i < str.length i++) {
System.out.print (Str[i] + "");
}
Results:
Boo and Foo
When limit=0, apply an infinite number of times and omit the empty string at the end
public static void Main (string[] args) {
String s = "Boo:and:foo";
string[] str = s.split ("o", -2);
for (int i = 0; i < str.length i++) {
if (I < str.length-1)
System.out.print ("+ str[i] +");
else
System.out.print ("(" + str[i] + ")");
}
Results:
(b), (), (: And:f), (), ()
public static void Main (string[] args) {
String s = "Boo:and:foo";
string[] str = s.split ("O", 0);
for (int i = 0; i < str.length i++) {
if (I < str.length-1)
System.out.print ("+ str[i] +");
else
System.out.print ("(" + str[i] + ")");
}
Results:
(b), (), (: And:f)
The above is the Java split data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!