VBScript If Statement - Trim X Letter after \

The script below captures the logged in user's domain and employee number.
This can be letters followed by a backslash \
e.g. ABC\12345
ABCD\123456
ABCDE\E539Z
etc.
The characters after the \ is the employee number.
The following line trims the domain and \, and keeps only the employee number:

UserID = Mid(UserID,instr(UserID,"\")+1)

Unfortunately there is an exception, and I need to add an if statement.
Some employee numbers have an X letter prefix, and I need to trim the X too.
For example if the employee number is X123456 I need only 123456 returned.
i.e if the logged in user is ABC\X123456 I need to trim ABC\X and leave only 123456

This is the only exception; for all the other logins I just need to trim the domain and \
like the script below shows.
Would you please help me out with an if statement that would do that for me?
Thank you.
<%
If Request.ServerVariables("LOGON_USER") = "" Then
Response.Status = "401 Access Denied"
Response.End
End If
%>
<%
set rs = Server.CreateObject("ADODB.recordset")
Dim UserID
UserID = Request.ServerVariables("LOGON_USER")

UserID = Mid(UserID,instr(UserID,"\")+1)



rs.Open "exec GetEmployees'" & UserID & "'", Conn

do until rs.EOF
Emp_Id = rs("Emp_Id")
First_Name = rs("First_Name")
Last_Name = rs("Last_Name")


rs.MoveNext
loop
rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing
%>

Employee Number: <%=Emp_Id%>
<br />
First Name: <%=First_Name%>
<br />
Last Name: <%=Last_Name%>

Open in new window

romsomIT DeveloperAsked:
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.

Martin LissOlder than dirtCommented:
Add this between lines 10 and 12.

UserId = Replace(UserId, "\X", "\")
0
byundtMechanical EngineerCommented:
If Left(UserID, 1) = "X" Then UserID = Mid(UserID, 2)           'Put after statement 12
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
UserID = Mid(UserID,instr(UserID,"\")+1)
if cstr(left(UserID,1))="x" or cstr(left(UserID,1))="X" then
     UserID=trim(right(UserID,len(UserID)-1))
end if
0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

romsomIT DeveloperAuthor Commented:
This was the only solution that worked for me, but thank you very much all of you.
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Thank you for the points!  

All the solutions here should work equally well.  I do like the solution by MartinLiss.  Perhaps this statement with the replace after you split out the UserID.

UserID = Mid(UserID,instr(UserID,"\")+1)
UserID= replace(UserID,"X")

At least you have it working.
0
romsomIT DeveloperAuthor Commented:
I've tried again all solutions and I see that the first two didn't work because the X is case sensitive. When I changed it to lower case, all three solutions worked.
I'm not sure how to make the first two solutions work both with lower case and upper case X
I will post the question.
Thanks again
0
romsomIT DeveloperAuthor Commented:
Yes, Byundt's solution worked like this:
If Left(UserID, 1) = "u" or Left(UserID, 1) = "U" Then UserID = Mid(UserID, 2)
0
Martin LissOlder than dirtCommented:
OK, you could have done this with mine.

UserId = Replace(UCase(UserId), "\X", "\")
0

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
romsomIT DeveloperAuthor Commented:
Thank you very much, I'm sorry I didn't distribute the points to all of you.
0
Martin LissOlder than dirtCommented:
It doesn't matter all that much to me but if you want to you can 'Request Attention' and ask the moderator to reopen the question so that you can do that.
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
If you want to spread the points, I think that is a good idea.  All  good.
0
romsomIT DeveloperAuthor Commented:
Thank you very much again; I'm really grateful to all of you.
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0
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
VB Script

From novice to tech pro — start learning today.