String. Split should be a function that is frequently used. The following two forms are often used:
Public String [] Split (char [] separator, stringsplitoptions options );
Public String [] Split (string [] separator, stringsplitoptions options );
1. In most cases, we use the first one,CodeMay be written in this way
String [] arr = Str. Split ("Abas". tochararray (), stringsplitoptions. removeemptyentries );
Note that when using this method, A, B, A, and s are all used as delimiters.
2. The second is to use the entire string element as the separator. This is newly added in. net2.0 and can generally be written as follows:
String [] arr = Str. Split (New String [] {"Abas"}, stringspliteoptions. removeemptyentries );
Sometimes we need to use the second form when maintaining aspx1.0, which can only be written by ourselves. Below is a function implementation similar to the second split method.
// ==================================
Private string [] splitstring (string V, string split)
{
Arraylist arr = new arraylist ();
Int P = V. indexof (split, 0 );
If (p <0)
{
Arr. Add (v );
}
While (P> = 0)
{
Arr. Add (V. substring (0, P ));
V = V. substring (p + split. Length );
P = V. indexof (split, 0 );
If (p <0 & V. length> 0)
{
Arr. Add (v );
Break;
}
}
Int empty = 0;
Foreach (string item in ARR)
{
If (item = "")
{
Empty ++;
}
}
String T = "". Split ();
String [] strarr = new string [arr. Count-empty];
Int J = 0;
For (INT I = 0; I <arr. Count; I ++)
{
If (ARR [I]. tostring ()! = "")
{
Strarr [J ++] = (string) Arr [I];
}
}
Return strarr;
}