C# split

C# Split divides a string, and return an array of substrings.

string s="Endmemo.com CSharp String Tutorial";
string[] arr=s.Split(' '); //divided by space
foreach(string elem in arr)
{
   ...
}
 //divided by letter t and T, case insensitive
string[] arr=s.Split('t',s, StringSplitOptions.IgnoreCase);

C# Split can use a substring as separator.
string s="'Endmemo.com','CSharp','23.432.32.6'";
//divided by substring ','
string[] arr=s.Split(new string[] {"','"}, StringSplitOptions.None); 
foreach(string elem in arr)
{
   ...
}

Regex.Split() can use regular expression as the separator.
string str = "<table width=\"100%\"><tr>123</tr><tr>abc</tr><tr>ZZZ</tr></table>";
string[] blocks = Regex.Split(str, @"\<\/tr\>", RegexOptions.IgnoreCase);

C# Split may change the special letters to hexadecimal NCR values. The following code will change special characters back.
elem = elem.Replace("&ldquo;", "\"");
elem = elem.Replace("\\""", "\"");
elem = elem.Replace("&rdquo;", "\"");
elem = elem.Replace("&amp;", "&");
elem = elem.Replace("&rsquo;", "'");
elem = elem.Replace("&mdash;", "-");

endmemo.com © 2020  Terms of Use | Home