Jump to content

Recommended Posts

Posted

Greetings,

I wish to find/read a line within a textfile that will look very similar to this:

As = -3.86E+000 Ag = 2.41E+000

I've got this code taken from another application written in C# and I'd like to be able to "duplicate" it using AutoIt...I'm not sure if the same commands are available:

int Find_As = line.IndexOf("As =");

int Find_Ag = line.IndexOf("Ag =");

if((Find_As != -1) && (Find_Ag != -1))

{

int ADJUST = Find_Ag; //used to properly exclude "text" from "DIFF1"

Find_As += 4; Find_Ag += 4; //add 4 "positions" in line to exclude "text"

string DIFF1 = line.Substring(Find_As, ADJUST - Find_As);

string DIFF2 = line.Substring(Find_Ag);

} //Find_As AND Find_Ag NOT -1

Basically what I'm trying to do is to "strip out" ONLY the NUMERIC values from the string above so as to write those values out to a simple .txt file...

Posted

Greetings,

I wish to find/read a line within a textfile that will look very similar to this:

As = -3.86E+000 Ag = 2.41E+000

I've got this code taken from another application written in C# and I'd like to be able to "duplicate" it using AutoIt...I'm not sure if the same commands are available:

int Find_As = line.IndexOf("As =");

int Find_Ag = line.IndexOf("Ag =");

if((Find_As != -1) && (Find_Ag != -1))

{

int ADJUST = Find_Ag; //used to properly exclude "text" from "DIFF1"

Find_As += 4; Find_Ag += 4; //add 4 "positions" in line to exclude "text"

string DIFF1 = line.Substring(Find_As, ADJUST - Find_As);

string DIFF2 = line.Substring(Find_Ag);

} //Find_As AND Find_Ag NOT -1

Basically what I'm trying to do is to "strip out" ONLY the NUMERIC values from the string above so as to write those values out to a simple .txt file...

StringRegExp() would be geekier, but this works fine:
$sString = "As = -3.86E+000 Ag = 2.41E+000"
If StringLeft($sString, 5) = "As = " Then 
    $iAg = StringInStr($sString, "Ag = ")
    If $iAg Then
        $DIFF1 = StringMid($sString, 6, $iAg - 6)
        $DIFF2 = StringMid($sString, $iAg + 5)
    EndIf
EndIf

MsgBox(64, "Results", "$DIFF1 = " & $DIFF1 & @CRLF & "$DIFF2 = " & $DIFF2)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

Thank you for the replies. Just so I understand:

Valuater your code basically cuts the string into 2 different strings "at the E" and then maniupulates the string a certain # of character positions to "weed out" the numbers only, correct?

And PsaltyDS you are searching for the "As = " and when found searching for the "Ag = " and then using the StringMid command to get positions to the right/left of those characters, correct?

Thanks again to both of you.

Posted

Basically what I'm trying to do is to "strip out" ONLY the NUMERIC values from the string above so as to write those values out to a simple .txt file...

$line = "As = -3.86E+000 Ag = 2.41E+000"
$linevars = StringRegExp ($line, "(?i)As = ([0-9a-f.\-\+]+) Ag = ([0-9A-F.\-\+]+)", 1)
$AS=$linevars[0]
$AG=$linevars[1]
MsgBox(0,"Result","AS: " & $AS & @CRLF & "Ag: " & $Ag)

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
×
×
  • Create New...