Jump to content
Sign in to follow this  

String help :(

Recommended Posts


I was messing around with strings today, everything worked fine until i tried to remove things from a string (got a bit complicated).

What i am trying to do is (example: "C:\downloads\test dir\file.jpg") to get the file name, in this case "file" to be seperated from the rest of the line. I can remove the last 4 letters, since its fairly easy with a line of code :P

$var = "C:\downloads\test dir\file.jpg"
$result = StringTrimRight($var, 4)

So now i have ""C:\downloads\test dir\file"

It got alot more complicated now and im not sure how to proceed to remove everything before the last "\". Tried using StringSplit and StringTrimRight, but never got the result i was looking for.

Thanks for any help on this.

"I'm paper, rock is fine, nerf scissors!!!"

Share this post

Link to post
Share on other sites

$total="C:\downloads\test dir\file"
$File = StringMid($total, StringInStr($total, "\", 0, -1) +1)

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
Live for the present,
Dream of the future,
Learn from the past.

Share this post

Link to post
Share on other sites

$var = StringSplit("C:\downloads\test dir\file.jpg", "\")
$no = $var[0]
$result = StringTrimRight($var[$no], 4)

Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post

Link to post
Share on other sites
The Kandie Man

Surprised nobody has brought up _PathSplit()

#include <file.au3>
#include <array.au3>
Dim $szDrive, $szDir, $szFName, $szExt
$TestPath = _PathSplit("C:\downloads\test dir\file.jpg", $szDrive, $szDir, $szFName, $szExt)
_ArrayDisplay($TestPath,"Demo _PathSplit()")

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.