954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Removing prefix XXX\username

I need to remove the prefix(domain name) if exist in front of a username from a session variable.


paramsql.Value = Session("ssNtUser")

say the domain is za

username is macupryk

I would like to remove the za\ so in the session variable I have

macupryk only but the domain name can change. Also there might not even be a domain name with a slash.


Thanks.

mcupryk
Newbie Poster
14 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 
string testString = Session("ssNtUser").ToString();

int i = testString.IndexOf("\\")+1;
			if(i > 0)
			{
				testString=testString.Substring(i);
			}
campkev
Posting Pro in Training
484 posts since Jul 2005
Reputation Points: 14
Solved Threads: 19
 

You could also try just running a split command on the string if it contains a backslash.

AlexClifford
Newbie Poster
8 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

I need to remove the prefix(domain name) if exist in front of a username from a session variable.

paramsql.Value = Session("ssNtUser")

say the domain is za

username is macupryk

I would like to remove the za\ so in the session variable I have

macupryk only but the domain name can change. Also there might not even be a domain name with a slash.

Thanks.

Hi,

U can use the split method of string object to get the username.string strUser = Session("ssNtUser") as string;
string[] strTemp = strUser.Split('\\');
if(strTemp.length > 0)
strUser = strTemp[strTemp.length - 1];
paramSql.Value = strUser;

Thanks,
Kedar

kedar_challa
Light Poster
47 posts since Nov 2005
Reputation Points: 10
Solved Threads: 1
 

vb.net : User.Identity.Name.Substring(User.Identity.Name.IndexOf("\") + 1)

asxcode
Newbie Poster
1 post since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You