Jump to content

Can autoit pull a variable from a string?


Go to solution Solved by sahsanu,

Recommended Posts

Posted

Can autoit pull a variable from a string?  I'm not sure how to phrase it and I've searched for it.

The user will pass in a name of a variable, $BOB.  And if $BOB matches a existing predefined variable, then the string will be replaced with the contents of the variable.  I'm thinking something along the lines of (below):  but $1 doesn't pull the contents of the variable.

$JOE = "192.168.1.45"
$BOB = "192.168.1.34"
$USERSTR = "ifconfig $BOB netmask 255.255.255.0"

$new = StringRegExpReplace( $USERSTR, "$(.*?) ", "$$1" & " ")
MsgBox(0, "IP", $new)

This outputs:  ifconfig $BOB netmask 255.255.255.0

Would like:  ifconfig 192.168.1.34 netmask 255.255.255.0

Thanks,

Dan

  • Solution
Posted (edited)

It is a really strange question but just in case...

$JOE = "192.168.1.45"
$BOB = "192.168.1.34"
$USERSTR = "ifconfig $BOB netmask 255.255.255.0"

$aSearchVariable = StringRegExp($USERSTR, "(\$.*?) ", 1)
$newip = Execute($aSearchVariable[0])
$new = StringRegExpReplace($USERSTR, "(\$.*?) ", $newip & " ")
MsgBox(0, "IP", $new)

Keep in mind that there is no error checks at all.

Cheers,

sahsanu

Edited by sahsanu
Posted

Thanks, much appreciated all. 

Execute($aSearchVariable[0]) and ExpandVarStrings works great.  I did not know what to search for and failed to come across these functions.

I'll be adding error checks.  Thanks again!

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
  • Recently Browsing   0 members

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