Question : Need to strip out the username from a Domain/username combination

I need to extract the username from domain/username combo derived using XPath Navigator (GetXPathNav). Unfortunately, I can't use basic string manipulation because the slash "/" is being translated as an escape sequence.
Code Snippet:
1:
2:
3:
4:
5:
// gets the Account ID
string userName = GetXPathNav("/my:myFields/my:group2/my:Person/my:AccountId").Value.ToString();
 
// this is not working because upon execution the slash is translated as an escape sequence
string userName = "DOMAIN\username".Replace('\',);

Answer : Need to strip out the username from a Domain/username combination

Hi,

You could either double the \ or put an @ before the string like so:

string userName = "DOMAIN\\username".Replace("\\","");
string userName = @"DOMAIN\username".Replace(@"\","");

But this will only replace the \ character. If you want tto get rid of DOMAIN also you could do like this:

int p = userName.IndexOf(@"\");
if (p > -1) userName = userName.Remove(0, p);


/peter
 
Random Solutions  
 
programming4us programming4us