Reputation: 3046
Got a bit of a mind freeze at the moment. I have the following syntax:-
string[] repname = Thread.CurrentPrincipal.Identity.ToString().Split('\');
and I get an error on the split character. Can anyone advise on how I can do the split using the \ character as the delimiter?
Cheers
Upvotes: 2
Views: 594
Reputation: 268344
Typically, the \
character is meant to escape other characters. If you wish it to be taken literally, you need to escape it with another \
. So, in order to escape on backslashes, you'll provide \\
.
Upvotes: 1
Reputation: 116090
\ is an excape character in C#.
You need to do one of the following:
Split('\\');
or
Split(@'\');
Upvotes: 1
Reputation: 28701
string[] repname = Thread.CurrentPrincipal.Identity.ToString().Split(new string[]{"\\"}, StringSplitOptions.None);
Upvotes: 0
Reputation: 11638
Split takes a char[] as a parameter, not a char. Try;
string[] repname = Thread.CurrentPrincipal.Identity.ToString().Split(new char[] {'\\'});
Upvotes: 1