JPJedi
JPJedi

Reputation: 1508

Error when splitting string with string

How can I split a string with a string?

string PostBuffer = "This Is First----WebKitFormBoundaryBBZbLlWzO0CIcUa6This Is Last"
string[] bufferarray =  PostBuffer.Split("----WebKitFormBoundaryBBZbLlWzO0CIcUa6", StringSplitOptions.None);

I get and error cannot convert Argument '1' from string to char and I get Argument '2' cannot convert from system.stringsplitoptions to char.

What am I doing wrong?

Upvotes: 1

Views: 1992

Answers (3)

m.edmondson
m.edmondson

Reputation: 30872

This is because the first argument is:

Type: System.String() An array of strings that delimit the substrings in this string, an empty array that contains no delimiters, or Nothing.

So you need to do:

string[] bufferarray = 
PostBuffer.Split(new string[] { "----WebKitFormBoundaryBBZbLlWzO0CIcUa6" }, StringSplitOptions.None);

You can read more from the docs.

Upvotes: 2

FishBasketGordo
FishBasketGordo

Reputation: 23132

There is no overload for string.Split which takes a string and StringSplitOptions as arguments. Do this instead:

string[] bufferarray = 
PostBuffer.Split(new string[] { "----WebKitFormBoundaryBBZbLlWzO0CIcUa6" }, StringSplitOptions.None);

Upvotes: 1

Jalal Said
Jalal Said

Reputation: 16162

PostBuffer.Split(new string[] { "----WebKitFormBoundaryBBZbLlWzO0CIcUa6"}, StringSplitOptions.None);

Upvotes: 4

Related Questions