Jump to content

Can autoit pull a variable from a string?


Go to solution Solved by sahsanu,

Recommended Posts

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

Link to comment
Share on other sites

Maybe you can use AutoItSetOption ( "ExpandVarStrings" , 1)

AutoItSetOption ( "ExpandVarStrings" , 1)

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

MsgBox(0, "IP", $USERSTR)
Link to comment
Share on other sites

  • Solution

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