Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I split a string in c# VB6-style without referencing Microsoft.VisualBasic?

Unfortunately, there seems to be no string.Split(string separator), only string.Split(char speparator).

I want to break up my string based on a multi-character separator, a la VB6. Is there an easy (that is, not by referencing Microsoft.VisualBasic or having to learn RegExes) way to do this in c#?

EDIT: Using .NET Framework 3.5.

like image 634
Josh Kodroff Avatar asked Aug 14 '26 09:08

Josh Kodroff


1 Answers

String.Split() has other overloads. Some of them take string[] arguments.

string original = "first;&second;&third";
string[] splitResults = original.Split( new string[] { ";&" }, StringSplitOptions.None );
like image 122
Joel B Fant Avatar answered Aug 17 '26 02:08

Joel B Fant



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!