Jump to content
Sign in to follow this  
bigdogdan2

Can autoit pull a variable from a string?

Recommended Posts

bigdogdan2

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

Share this post


Link to post
Share on other sites
Palestinian

$var = "$BOB"
If $x = "$BOB" Then
$var = "192.168.1.34"

 

Something like that? I'm sure others will give you a better way to do it, but you could check that for a start.

Share this post


Link to post
Share on other sites
jguinch

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)
  • Like 1

Share this post


Link to post
Share on other sites
sahsanu

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
  • Like 1

Share this post


Link to post
Share on other sites
bigdogdan2

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!

Share this post


Link to post
Share on other sites
Malkey

You might consider this.

Local $JOE = "192.168.1.45"
Local $BOB = "192.168.1.34"

Local $USERSTR = "ifconfig " & $BOB & " netmask 255.255.255.0"
MsgBox(0, "IP 0", $USERSTR)

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  

×