olca02
asked on
String handling, trim a string in c#
Hi.
I have some difficulties finding the right technique using strings in c# i hope somebody can help.
I have several domain\usernames which i need to have left trimmed. Right now the string is domain\username i only want the username to be visible. My issues is that the domain is not having the same length each time
domain-ch\username
domain.com\username
domain.it\username etc.
What do i need to do, for just ending up with the username and get rid of domain..\. Thanx every help is appreciated.
I have some difficulties finding the right technique using strings in c# i hope somebody can help.
I have several domain\usernames which i need to have left trimmed. Right now the string is domain\username i only want the username to be visible. My issues is that the domain is not having the same length each time
domain-ch\username
domain.com\username
domain.it\username etc.
What do i need to do, for just ending up with the username and get rid of domain..\. Thanx every help is appreciated.
System.IO.Path.GetFilename ("domain\u sername") might work.
Hi,
if you are working with strings use the Split method, like this:
if you are working with strings use the Split method, like this:
//creating the string
string Test = @"domain\user";
//creating the split character
char[] split = {'\\'};
//the [1] is to pick up the second part
// [0] = domain
// [1] = user
string user = Test.Split(split)[1];
As an additional note, you might want to comment what is going on when you use that function as you are not technically parsing a filename ;)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.