String Split method, very early used, but today in the forum to see others mentioned problems, or let me very confused. Therefore, the relevant information was found and summarized as follows:
First, look up the overloaded methods for split in MSDN:
Overloaded List
name |
Description |
String.Split (char[]) |
returns a string array that contains the substrings in this instance delimited by the elements of the specified Char array. Supported by the. NET Compact Framework. |
String.Split (char[], Int32) |
returns a string array that contains the substrings in this instance delimited by the elements of the specified Char array. parameter specifies the maximum number of substrings to return. |
String.Split (char[], stringsplitoptions) |
returns a string array that contains the substrings in this string that are delimited by the elements of the specified Char array. parameter specifies whether to return an empty array element. |
String.Split (string[], stringsplitoptions) |
returns a string array that contains the substrings in this string separated by the elements of the specified string array. parameter specifies whether to return an empty array element. |
String.Split (char[], Int32, stringsplitoptions) |
returns a string array that contains the substrings in this string that are delimited by the elements of the specified Char array. parameter specifies the maximum number of substrings to return and whether to return an empty array element. |
String.Split (string[], Int32, stringsplitoptions) |
returns a string array that contains the substrings in this string separated by the elements of the specified string array. parameter specifies the maximum number of substrings to return and whether to return an empty array element. |
Limited to the length of the question, I only give the first example of the explanation. The rest of you are going to see MSDN.
Grammar:
Public string[] Split (
params char[] separator
)
Parameters:Separator
An array of Unicode characters that delimit the substring of this instance, an empty array that contains no delimiters, or a null reference (Nothing in Visual Basic). return Value:
An array whose elements contain substrings in this instance that are delimited by one or more characters in the separator. For more information, see the Remarks section.
Note:
The separator character is not included in the element that returns an array of values. The delimiter is detected using the ordinal comparison.
If this instance does not contain any characters in the separator, the return value array consists of a single element that contains this instance. If the separator parameter is a null reference (Nothing in Visual Basic) or contains no characters, white space is used as the separator.
If two delimiters are adjacent, or if the delimiter is found at the beginning or end of this instance, the corresponding array element contains Empty (String.Empty field: Represents an empty string. This field is read-only).
The members of the StringSplitOptions class are selected in the following two categories:
|
Description | of
member name |
|
None |
The return value includes an array element containing an empty string |
|
Removeemptyentries |
The return value does not include an array element that contains an empty string |
Example:
Using System; public class Splittest {public static void Main () {String words = ' This is a list of words, with:a bit of punctuation. ' ; string [] split = words. Split (New Char [] {', ', ', ', ', ', ', ', ', '; ', ': '}); foreach (string s in Split) {if (S.trim ()!= "") Console.WriteLine (s);}}}
Output results:
This
Is
A
List
Of
Words
With
A
Bit
Of
Punctuation
Write here actually not finished, but there are some results, I still can not very good explanation, so do not come clean.