I have a issue when I look up a user name using the code below if the user has \v in their name. For Example, if their user name is xxx\vtest, it can’t find the backslash when using the LastIndexOf function.
string strUser = this.Context.User.Identity.Name;
strUser = strUser.Substring(strUser.LastIndexOf("\\") + 1);
If I do try this, it works with no problems.
string strUser = @"xxx\vtest";
strUser = strUser.Substring(strUser.LastIndexOf("\\") + 1);
Any ideas on how to ignore the escape character while using User.Identity.Name?
If the name has ‘backslash v’ you should find a backslash, if the name has a vertical tab (escaped ‘\v’) you will not find a backslash. The reason you find a backslash in the second version is because you used an @ with the string declaration more info.
try this:
EDITED
If you know which escape characters you are looking for you can also use this:
If you know that there is exactly one character that follows the domain you can also use Regex to get the user.