Monday, March 26, 2012

string.Split() does not work?

The following code:

string strProductIDAndProductCategory = Convert.ToString(e.CommandArgument); // productidandproductcategory sent in the command argument
string [] strArrayProductIDAndProductCategory = strProductIDAndProductCategory.Split("/");

...gives me the following compile error:
The best overloaded method match for 'string.Split(params char[])' has some invalid arguments

What are these 'invalid arguments'?

when i change it from Split("/") to Split() it works just fine... what gives?

thanks"/" is a string and not a char[]

Try this


char[]splitOn = {'/'};
string [] strArrayProductIDAndProductCategory = strProductIDAndProductCategory.Split(splitOn);

or this

string [] strArrayProductIDAndProductCategory = strProductIDAndProductCategory.Split('/');

0 comments:

Post a Comment