Jump to content
Sign in to follow this  
jebus495

Removing something from a string

Recommended Posts

jebus495

$Input1 = GUICtrlCreateInput("C:\Program Files\Diablo II\Game.exe", 8, 31, 217, 21)

$d2_dir = GUICtrlRead($Input1)

I need to remove the last part of this string so that all that remains is "C:\Program Files\Diablo II\" because I need to use this directory later in my script to move files to.

The input will not always be "C:\Program Files\Diablo II\Game.exe" and the .exe can also change.

I think I might end up needing RegExp but I'm totally lost in that crap...

Share this post


Link to post
Share on other sites
exodius

It can be done pretty simply...

$varExecutable = "C:\Program Files\Diablo II\Game.exe"
$split = StringSplit ($varExecutable, "\")
$varLocation = StringReplace ($varExecutable, "\" & $split[$split[0]], "")
;~ $Input1 = GUICtrlCreateInput($varExecutable, 8, 31, 217, 21)
;~ $d2_dir = GUICtrlRead($Input1)

MsgBox (0, "", $varExecutable & @CRLF & $varLocation)

Share this post


Link to post
Share on other sites
jebus495

It can be done pretty simply...

$varExecutable = "C:\Program Files\Diablo II\Game.exe"
$split = StringSplit ($varExecutable, "\")
$varLocation = StringReplace ($varExecutable, "\" & $split[$split[0]], "")
;~ $Input1 = GUICtrlCreateInput($varExecutable, 8, 31, 217, 21)
;~ $d2_dir = GUICtrlRead($Input1)

MsgBox (0, "", $varExecutable & @CRLF & $varLocation)

Wow TY it works perfectly!

I read pretty much every string function in the helpfile spending extra time reading through StringReplace and StringSplit and just couldn't figure out how to make it do what I wanted.

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  

×