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)
{
   ...
}

C# split may change the special letters to hexadecimal NCR values. The following code will change special characters back.
elem = elem.Replace("“", "\"");
elem = elem.Replace("\\""", "\"");
elem = elem.Replace("”", "\"");
elem = elem.Replace("&", "&");
elem = elem.Replace("’", "'");
elem = elem.Replace("—", "-");

endmemo.com © 2020  Terms of Use | Home