Jump to content

Removing something from a string


 Share

Recommended Posts

$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...

Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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.

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...