small func: convert from to c#

   Public Function NTUserID() As String
        Dim sId As String
        Dim strMsg As String
        Dim ipos As Integer
        sId = Request.ServerVariables("logon_user")
        ipos = Len(sId) - InStr(1, sId, "\")
        sId = Right(sId, ipos)
        Return sId
    End Function
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alldayAuthor Commented:
the Request.ServerVariables("logon_user") returns me


i just need >>> mJohn
Jeff CertainCommented:
string logon = Request.ServerVariables("logon_user");
Jeff CertainCommented:
oops... forgot about the indexes..

string logon = Request.ServerVariables["logon_user"];
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

alldayAuthor Commented:
logon.Substring(logon.IndexOf("\")+1);  <<<<--GETTING ERROR  : Newline in constant

Note the double slash...

...hope that solves it.
alldayAuthor Commented:
i did try with double slash too but it does not  return the desired result

for an example:

i'm getting logon_user  -- US\UserName

i want to trim "US\"

and get the only UserName

when i use the double slash it does not trim "US\" rather it gives me "US\UserName"

hope im clear


allday, try:

// Get username
DomainAndUsername = ...
string UserName = DomainAndUsername.Substring(DomainAndUsername.IndexOf(@"\") + 1);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.