Class t {
Public static void main (string ARGs []) {
String num [] = new string [11];
String Sline = "101494 | 360103660318444 | 2008/06/17 | Zhou runying | 1292.0 | 3085.76 | 2778.28 | 912.91 | 106.0 | ";
Num = Sline. Split ("\\| ");
Int ROW = 1;
For (string S: num ){
System. Out. println (row ++ "=" + S );
}
}
}
There are three |, and the running result is
1 = 101494
2 = 360103660318444
3 = 2008/06/17
4 = Zhou runying
5 = 1292.0
6 = 3085.76
7 = 2778.28
8 = 912.91
9 = 106.0
Check the API. There is a Public String [] Split (string RegEx, int limit );
The limit parameter controls the number of application modes, thus affecting the length of the result array.
If the limit N is greater than zero, The pattern applies n>-1 times at most, the length of the array is not greater than N, and the last entry of the array will contain all input except the last matching delimiter.
If n is not positiveThe number of application modes is unlimited, and the array can be of any length.
If n is zeroThe number of times in the application mode is unlimited. The array can be of any length and the trailing null string will be discarded.
Modify the code to class t {
Public static void main (string ARGs []) {
String num [] = new string [11];
String Sline = "101494 | 360103660318444 | 2008/06/17 | Zhou runying | 1292.0 | 3085.76 | 2778.28 | 912.91 | 106.0 | ";
Num = Sline. Split ("\ |",-1); // here-1 is used as the parameter
Int ROW = 1;
For (string S: num ){
System. Out. println (row ++ "=" + S );
}
}
}
The running result is
1 = 101494
2 = 360103660318444
3 = 2008/06/17
4 = Zhou runying
5 = 1292.0
6 = 3085.76
7 = 2778.28
8 = 912.91
9 = 106.0
10 =
11 =
12 =
The result is normal.