Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove the DomainName from User.Identity.Name 1

Status
Not open for further replies.

Mike555

Technical User
Feb 21, 2003
1,200
0
0
US
User.Identitiy.Name identifies the DomainName\UserName of a user. Is there an easy way to remove the DomainName portion so that only the UserName is listed? Thanks.

Regards,
Mike

"Don’t get suckered in by the comments – they can be terribly misleading. Debug
only code. – Dave Storer."
 
If you just read the value into a string you can find where the slash begins and take a substring of the original string. e.g.
Code:
        Dim MyString As String = "MyDomain\MyUser"
        Dim x As Integer = MyString.IndexOf("\") + 1
        Dim y As Integer = MyString.Length
        MyString = MyString.Substring(x, y - x)
You can even simplify this (I just wanted to easily show how it was done) and use something like:
Code:
        Dim MyString As String = "MyDomain\MyUser"
        MyString = MyString.Substring(MyString.IndexOf("\") + 1, MyString.Length - (MyString.IndexOf("\") + 1))

Hope this helps.



----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I keep this in a class with some other utilities and just pass in the Context.User.Identity.Name
Code:
public string getLanID(string LanID)
{
int pos = LanID.IndexOf("\\");
string newLanID = LanID.Substring(pos+1);
return newLanID;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top