Public String [] Split (string RegEx, int limit) Splits a string based on a regular expression.
The array returned by this method contains each substring of this string, which is terminated by another substring that matches the given expression or ends by the string. The substrings in the array are arranged in the order of the strings. If the expression does not match any part of the input, the result array has only one element, that is, this string.
The limit parameter controls the number of times that the mode applies, thus affecting the length of the result array. If the limit N is greater than 0, the mode will be applied N-1 times at most, and the length of the array will not be greater than N, in addition, the last entry of the array will contain all input that exceeds the last matching delimiter. If n is not positive, the pattern will be applied as many times as possible, and the array can be of any length. If n is zero, the mode will be applied as many times as possible, the array can have any length, and the trailing null string will be discarded.
Example 1:
Public class splitdemo {
Public static string [] Ss = new string [20];
Public splitdemo (){
String S = "The rain in Spain falls mainly in the plain .";
// Separate each space character.
Ss = S. Split ("");
}
Public static void main (string [] ARGs ){
Splitdemo demo = new splitdemo ();
For (INT I = 0; I <ss. length; I ++)
System. Out. println (SS );
}
}
Program result:
The
Rain
In
Spain
Falls
Mainly
In
The
Plain.
Example 2:
Public class splitdemo {
Public static string [] Ss = new string [20];
Public splitdemo (){
String S = "The rain in Spain falls mainly in the plain .";
// Separate each space character.
Ss = S. Split ("", 2 );
}
Public static void main (string [] ARGs ){
Splitdemo demo = new splitdemo ();
For (INT I = 0; I <ss. length; I ++)
System. Out. println (SS );
}
}
Program result:
The
Rain in Spain falls mainly in the plain.
Example 3:
Public class splitdemo {
Public static string [] Ss = new string [20];
Public splitdemo (){
String S = "The rain in Spain falls mainly in the plain .";
// Separate each space character.
Ss = S. Split ("", 20 );
}
Public static void main (string [] ARGs ){
Splitdemo demo = new splitdemo ();
For (INT I = 0; I <ss. length; I ++)
System. Out. println (SS );
}
}
Program result:
The
Rain
In
Spain
Falls
Mainly
In
The
Plain.
Example 4:
Public class splitdemo {
Public static void main (string [] ARGs ){
String value = "192.168.128.33 ";
String [] names = value. Split (".");
For (INT I = 0; I <names. length; I ++ ){
System. Out. println (names );
}
}
}
Running result:
Yes. No error! No output!
Http://blog.csdn.net/lizhengnanhua/article/details/7994159