Splitting string with string C# .net 1.1.4322
How do I split a string with a string in C# .net 1.1.4322?
String example:
开发者_如何转开发Key|Value|||Key|Value|||Key|Value|||Key|Value
need:
Key|Value
Key|Value
Key|Value
I cannot use the RegEx.Split because the separating character is the ||| and just get every character separately.
I cannot use the String.Split() overload as its not in .net 1.1
Example of Accepted solution:
using System.Text.RegularExpressions;
String[] values = Regex.Split(stringToSplit,"\\|\\|\\|");
What about using @"\|\|\|" in your Regex.Split call? That makes the | characters literal characters.
One workaround is replace and split:
string[] keyvalues = "key|value|||key|value".replace("|||", "~").split('~');
here is an example:
System.Collections.Hashtable table;
string[] items = somestring.split("|||");
foreach(string item in items)
{
string[] keyvalue = item.split("|");
table.add(keyvalue[0],keyvalue[1]);
}
string input = "Hi#*#Hello#*#i#*#Hate#*#My#*#......" ;
string[] delim = new string[] { "#*#" };
string[] results = input.split(delim , StringSplitOptions.None);
精彩评论