split on \ char????

  • Thread starter Thread starter merrittr
  • Start date Start date
M

merrittr

i am trying to split the contents of a textbox
(the value will be a filespec path so \ are included)
anyway how do I split on the \?

strFileNameOnServer = uplTheFile.Value;
char[] sep = @"\";
string[] arrStr=strFileNameOnServer.Split(sep);
strFileNameOnServer = arrStr[arrStr.Length].ToString();
 
Hello,

you could just do:

string[] arrStr = strFileNameOnServer.Split({@'\'});

This is untested, you may have to remove the @ and escape the \ with
another, like:

string[] arrStr = strFileNameOnServer.Split({'\\'});

HTH
 
you could just do:

string[] arrStr = strFileNameOnServer.Split({@'\'});

This is untested, you may have to remove the @ and escape the \ with
another, like:

string[] arrStr = strFileNameOnServer.Split({'\\'});

Putting the character in braces like that doesn't create a char array.
However, because String.Split takes a "params" argument, you can just
use:

string[] arrStr = strFileNameOnServer.Split('\\');
 
Back
Top