Literals

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Folks,
I am trying to parse out a string which contains the User.Identity.Name
which results in something like mydomain\me. So when I do somethong like
trying to find where the backslash is by:

suser = User.identity.Name
iPos = sUser.LastIndexOf(@"\",1)

It never finds the backslash! If I set sUser = @"mydomain/me" it works fine,
but the user name comes from User.Identity.Name and I cannot seem to get the
@ sign prepended so that it works correctly.

Hope you cna help
 
Shem said:
Hi Folks,
I am trying to parse out a string which contains the
User.Identity.Name which results in something like mydomain\me. So
when I do somethong like trying to find where the backslash is by:

suser = User.identity.Name
iPos = sUser.LastIndexOf(@"\",1)

It never finds the backslash! If I set sUser = @"mydomain/me" it
works fine, but the user name comes from User.Identity.Name and I
cannot seem to get the @ sign prepended so that it works correctly.

Hope you cna help

The "@" is just a signal to the compiler. You use that on fixed strings
that contain special characters.
If "User.Identity.Name" returns the name with a "\", then there *is* a backslash,
just as if you typed @"mydomain\me".

I think the problem is in the second parameter to LastIndexOf: it starts the search
at the second character and searches to the beginning! Remove that ",1" and
it should work.

Hans Kesting
 
Hi Shem

Did you mean sUser.LastIndexOf(@"\", sUser.Length)? LastIndexOf searches
backwards, in your example from 1 to 0.

Regards,
Serge
 
Try this
this works for me

sDomainUserName = User.Identity.Name.ToString();
int iPos = sDomainUserName.LastIndexOf("\\");

Arun
 
I think the problem is with the second paramter of LastIndexOf. LastIndexOf
searches *backwards* from this position, so it's only looking at the first
two characters of sUser!

Chris Jobson
 
Back
Top