bigdogdan2 Posted April 9, 2014 Posted April 9, 2014 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
Palestinian Posted April 9, 2014 Posted April 9, 2014 $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.
jguinch Posted April 9, 2014 Posted April 9, 2014 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) bigdogdan2 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Solution sahsanu Posted April 9, 2014 Solution Posted April 9, 2014 (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 April 9, 2014 by sahsanu bigdogdan2 1
bigdogdan2 Posted April 9, 2014 Author Posted April 9, 2014 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!
Malkey Posted April 10, 2014 Posted April 10, 2014 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)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now