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.

string testString = Session("ssNtUser").ToString();

int i = testString.IndexOf("\\")+1;
			if(i > 0)
			{
				testString=testString.Substring(i);
			}

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

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

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