Question : Split with character \

I've just started working with C#.

I'm trying to split a string into an array at the point where the string has a slash character \  

But it seems to be a special little slash to C# because if I try to use this line

string[] arrUsername = RemoteUser.ToString().Split(("\").ToCharArray());

The text after the character turns a different color and VS tells me I'm starting a new line there ("new line in constant").

My attempts to code it alternatively as ASCII character 92 are met with "  'char' is a type but is used like a 'variable'   ", which I don't understand (background is VB.NET)

Is there another way I could code this line ?


Christian



(Here's the definition of RemoteUser, a local string I'm trying to split in that line)
 
string RemoteUser = Request.ServerVariables["REMOTE_USER"];

Answer : Split with character \

Hi CAWhite;

In C# the \ in a string is an escape character. To have the compiler to ignore it in a string use the @ sign as below.

string[] arrUsername = RemoteUser.ToString().Split((@"\").ToCharArray());

Fernando

Random Solutions  
 
programming4us programming4us