×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

get the word after backslash
2

get the word after backslash

get the word after backslash

(OP)
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,
 

RE: get the word after backslash

Hi,

this should work.

yourString = D123\UNIX

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

Regards
Jacqui
 

RE: get the word after backslash

Another way:

CODE

yourString = "D123\UNIX"

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

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

http://lessthandot.com  

RE: get the word after backslash

(OP)
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

RE: get the word after backslash

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.

http://lessthandot.com  

RE: get the word after backslash

(OP)
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,

RE: get the word after backslash

Did you try my suggestion?

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

http://lessthandot.com  

RE: get the word after backslash

(OP)
yeah, but your suggestion couldn't handle the last example:

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

 

RE: get the word after backslash

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.

http://lessthandot.com  

RE: get the word after backslash

(OP)
I found something like this:

Split(yourString, "\").Last();

RE: get the word after backslash

Yep, that's a nicer way of doing what my last post did smile

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

http://lessthandot.com  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close