Jump to content
Sign in to follow this  
EndFunc

StringinStr an d StringRight..

Recommended Posts

EndFunc

Ok I've been trying to trim a UNC path and getting stumped. Sometimes I can get the hardest things and the things I think should be easy, I get stumped. LOL

Well say I have a unc path

\\pathtomyscript\users\

I want to take off the last \ on that string.

That was easy enough using stringinstr but then, it would still count any \ it finds and trims the last letter. I only want it to trim the last slash if its there if its not the last character in the string then do nothing.

I tried

$Path = "\\pathtomyscript\users\"
If StringinStr($Path, "\", "2", "-1", "1", "1") Then
$tPath = StringTrimRight($Path, "1")
End

So the result I want to be \\pathtomyscript\users but only if the string had a \ on the end to begin with.

But that only works if the \ is on the end. If it's not it removes the s in users. I can't figure out how to not process this if there is a \ on the end only.

Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites
SmOke_N

Or just one function call:

$Path = StringRegExpReplace($Path, "\\+\z", "")

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
EndFunc

If StringRight($Path, 1) = "\" Then $Path = StringTrimRight($Path, 1)

Seriously? LOL told you it was easy. I was close. I guess I really need a better understanding of how some of these string commands work.

Thanks for quick response.


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites
EndFunc

Or just one function call:

$Path = StringRegExpReplace($Path, "\\+\z", "")

I would never get this on my own. I am fairly decent using the String commands but Regular expression is just even more greek. I leave with a headache. :) lol

Thanks again.

Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites
PsaltyDS

...but Regular expression is just even more geek.

Corrected your spelling.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×