Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get the word after backslash 2

Status
Not open for further replies.

peac3

Technical User
Jan 17, 2009
226
0
0
AU
Hi Guys,

This should be easy to some of you:

I am trying to get the word after backslash (\) like example:
D123\UNIX output UNIX
D1\LINUX output LINUX
b1098\WINDOWS output WINDOWS

Can you guys please help?

Thanks,
 
Hi,

this should work.

yourString = D123\UNIX

outputstring = yourString.Substring(yourString.IndexOf('\\') + 1);

Regards
Jacqui
 
Another way:
Code:
yourString = "D123\UNIX"

outputString = Split(yourString, "\")(1)
Hope this helps

Andy
---------------------------------
Zebracorn: 50% Zebra, 50% Unicorn = 100% Real.

 
Thanks Guys,

I just realised that our string has double backslash at the beginning, so for example:

\\D123\UNIX output UNIX
\\D1\LINUX output LINUX
\\b1098\WINDOWS output WINDOWS

sorry for confusion before
 
That's no problem, if you change the (1) to (3) in my code that should sort it for you.

Hope this helps

Andy
---------------------------------
Zebracorn: 50% Zebra, 50% Unicorn = 100% Real.

 
the string could be two backslashes like:

\\D123\UNIX output UNIX
\\D1\LINUX output LINUX
\\b1098\WINDOWS output WINDOWS
\\b1098\WINDOWS\folder output folder

So basically Im trying to get the word after the last backslash...

Thanks in advance guys,
 
yeah, but your suggestion couldn't handle the last example:

\\b1098\WINDOWS\folder the output is WINDOWS instead of folder

 
There are more elegant ways, but to make it work that way with my suggestion, try something like:
Code:
Split(yourString, "\")(UBound(Split(yourString, "\")))
Hope this helps

Andy
---------------------------------
Zebracorn: 50% Zebra, 50% Unicorn = 100% Real.

 
I found something like this:

Split(yourString, "\").Last();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top