Jump to content

Strings


Recommended Posts

ok ill try to explain

$var1=C:\Program Files\WinRAR\winrar.exe

I want

$var2 to equal the file name in this case "winrar.exe" and I want

$var3 to equal the path in this case "C:\Program Files\WinRAR\"

does anyone know how to do this I tried

$var2 = Stringright($var1, StringInStr($var1, '\', 0, -1) -1)

Help

Link to comment
Share on other sites

Try this

$var1="C:\Program Files\WinRAR\winrar.exe"

$var2 = StringRight($var1, StringLen( $var1 ) - StringInStr($var1, '\', 0, -1) )
$var3 = StringLeft($var1, StringInStr($var1, '\', 0, -1) )

MsgBox( 0, "", $var1 & @CR & $var2 & @CR & $var3 )

hope that clears everything up

Edited by Don N

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

Try

$var1 = "c:\Program Files\WinRAR\winrar.exe"
$sect = StringSplit($var1,"\")
$var2 = $sect[1] & "\" & $sect[2] & "\" & $sect[3]
MsgBox(0,"",$var2)
$var3 = $sect[4]
MsgBox(0,"",$var3)


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

Link to comment
Share on other sites

For variable length path you can use mine or this modified version of bigdod's

$var1 = "c:\Program Files\WinRAR\winrar.exe"
$sect = StringSplit($var1,"\")
$var2 = ""
For $i = 1 To UBound( $sect ) - 2
        $var2 = $var2 & sect[$i] & "\"
Next
MsgBox(0,"",$var2)
$var3 = $sect[UBound($sect) - 1]
MsgBox(0,"",$var3)

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...