Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting string with string C# .net 1.1.4322

Tags:

c#

split

.net-1.1

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,"\\|\\|\\|");
like image 627
Dilbert789 Avatar asked Dec 02 '25 21:12

Dilbert789


2 Answers

What about using @"\|\|\|" in your Regex.Split call? That makes the | characters literal characters.

like image 82
jjxtra Avatar answered Dec 04 '25 11:12

jjxtra


One workaround is replace and split:

string[] keyvalues = "key|value|||key|value".replace("|||", "~").split('~');
like image 36
Joel Avatar answered Dec 04 '25 11:12

Joel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!