Jump to content

unkown string in a string in a file


Recommended Posts

I'm attemping to place an unknown string into a variable from a file.

By unknown, I mean it is going to be different each time and after "something=" and be composed of 8 numbers dot 3 numbers. It will be in a file but not necessarily the same number of lines in each time. Example file

[somethin]
something1=whatever
something7=whatever
something4=56354569.654
something2=die
something6=now

[somethin2]
something11=whatever
something77=whatever
something44=56354569.654
something22=die
something66=now

I'd like to make the variable the first instance of "56354569". I've tried experimenting with readfile and stringinstr but I'm stumped...

Thanks in advance for any help!

This signature is computer generated, nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#.......

Link to comment
Share on other sites

Hi,

Dirty, using DOS;

FINDSTR /R/I /c:"[0-9]*[.][0-9][0-9][0-9]" "@ScriptDir\somethin.txt">"@ScriptDir\Answer.txt"

then retrieve the first line from "@ScriptDir\Answer.txt"; "=" to "." not inclusive.!

Best, Randall

(We shouldn't resort to DOS; just familiar?)

;--------------- FINDSTRAU3 Example; Randall Clapp randallc@ozemail.com.au ---------------

#include <file.au3>

Dim $DosFINDSTRReturn,$Display

Opt("RunErrorsFatal", 0)

;FINDSTR /R/I  /c:"[0-9]*[.][0-9][0-9][0-9]" "@ScriptDir\somethin.txt">"@ScriptDir\Answer.txt"

$DefSwitches="/R/I  /c:"&chr(34)&"[0-9]*[.][0-9][0-9][0-9]"&chr(34)      ; Change only if you know FINDSTR switches well

$FileIndiv=@ScriptDir&"\somethin.txt"

$Answer=@ScriptDir&"\Answer.txt"

FINDSTRAU3($DefSwitches,$FileIndiv,$Answer)

$sFilePath1=$Answer

FileOpen($sFilePath1,1 )

$line = FileReadLine($sFilePath1)

FileClose($sFilePath1)

$pos1=StringInStr($line,"=")

$pos2=StringInStr($line,".")

$8nums=stringmid($line,$pos1+1,$pos2-$pos1-1)

msgbox(0,"$8nums=",$8nums)

Exit

;--------------- FINDSTRAU3 function; Randall Clapp randallc@ozemail.com.au  ---------------

Func FINDSTRAU3($Switches, $File,$AnswerFile)

If StringInStr($File, " ") Then $File = '"' & $File & '"'

If StringInStr($AnswerFile, " ") Then $AnswerFile = '"' & $AnswerFile & '"'

$Command = @ComSpec & " /c " & 'FINDSTR '& $Switches &' '& $File &'>'&$AnswerFile

$DosFINDSTRReturn=RunWait($Command, @SystemDir, @SW_HIDE)

EndFunc  ;==>FINDSTRAU3

Edited by randallc
Link to comment
Share on other sites

Iniread should do the trick! Thanks, autoit rules...

Edited by anystupidassname

This signature is computer generated, nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#.......

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