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.

5
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by asxcode
0
string testString = Session("ssNtUser").ToString();

int i = testString.IndexOf("\\")+1;
			if(i > 0)
			{
				testString=testString.Substring(i);
			}
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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.