ghanshyam.mirani
ghanshyam.mirani

Reputation: 3101

How to call String.Split that takes string as separator?

I have following string value: AnnualFee[[ContactNeeYear that I want to split using separator : "[["

The MSDN topic String.Split says that such function exists, so i used following code :

oMatch.Groups[0].Value.Split('[[');

but it throws an error saying:

Can not implicitly convert string[] to string

so how to split string value with separator : "[["

Upvotes: 3

Views: 357

Answers (3)

zey
zey

Reputation: 6105

In a short way ,

string yourString = "AnnualFee[[ContactNeeYear";  
string [] _split = yourString.Split(new string[] { "[[" }, StringSplitOptions.None);

Upvotes: 0

Hitesh
Hitesh

Reputation: 3860

Try below code, it has worked for me:

        string abc = "AnnualFee[[ContactNeeYear";

        string[] separator = { "[[" };

        string[] splitedValues = abc.Split(separator , StringSplitOptions.None);

I hope it will help you.. :):)

Upvotes: 4

Farhad Jabiyev
Farhad Jabiyev

Reputation: 26635

string text= "AnnualFee[[ContactNeeYear";
string[] parts= Regex.Split(text, @"\[\[");

The result is:

AnnualFee
ContactNeeYear

You can use Regex.Split(text, pattern) for such purpose.

Upvotes: 2

Related Questions