You can split the three parts:
var splitted = userName.Split(new char[] {'\\', '/'});
Where split[0]
would be your prefix (ABC
), split[1]
will be your domain (Domain-name
) and split[2]
will be your username (Pinto
)
I've made a fiddle: https://dotnetfiddle.net/zvbwZi
Alternatively, you can substring it:
To get the prefix and the username (e.g. ABC\Pinto
):
var prefix = userName.Substring(0, userName.IndexOf('/'));
var user = userName.Substring(userName.LastIndexOf('\\'));
var prefixAndUser = prefix + user;
Then to get just the username (e.g. Pinto
):
var userNameWithoutPrefixOrDomain = user.Substring(1);
Or if you want the forward slash (ABC/Pinto
):
var prefix = userName.Substring(0, userName.IndexOf('/')+1);
var user = userName.Substring(userName.LastIndexOf('\\')+1);
In this case, user
will already be your username
I've made a fiddle too: https://dotnetfiddle.net/7YL0m5