BrettF Posted January 15, 2007 Share Posted January 15, 2007 Say i have a file with the lines: a b123 c d234 e.... and i didnt know what line d234 was on. How would i find it? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 15, 2007 Moderators Share Posted January 15, 2007 _FileReadToArray() + Loop + StringInString() Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
BrettF Posted January 15, 2007 Author Share Posted January 15, 2007 Thanks. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
flyingboz Posted January 15, 2007 Share Posted January 15, 2007 (edited) Say i have a file with the lines:by parsing the file, looking for the line. (duh) One method (pseudocode / untested / no error checking) uses FileRead,StringInStr,StringLeft,and StringReplace $contents = FileRead($filename,filegetsize($filename)) $line = "this is a matching line" $line_delimiter = @CRLF $match = StringInStr($contents,$line) If Not $match then exit 0 else StringReplace(StringLeft($contents,$line),$line_delimiter,"") exit @extended endif Edited January 15, 2007 by flyingboz Reading the help file before you post... Not only will it make you look smarter, it will make you smarter. Link to comment Share on other sites More sharing options...
GEOSoft Posted January 15, 2007 Share Posted January 15, 2007 If you are going to #include <array.au3> Then also take a look at the _Array Search() function George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 15, 2007 Moderators Share Posted January 15, 2007 This may make it simple... the _ArrayDisplay2d is just to show you, isn't needed for the function. Input the file to search, the string to find, and 1 in the $iCase parameter if you want the search case sensitive. It will return a 2 dimensional array, the [0] will contain the line number found, and the [1] will display the actual line itself. CODEexpandcollapse popup$a = _StringReturnLine('somefile.txt', 'some text') _ArrayDisplay2d($a) Func _StringReturnLine($hFile, $sFind, $iCase = 0) If Not FileExists($hFile) Then Return SetError(1, 0, 0) Local $aSplit = StringSplit(StringStripCR(FileRead($hFile)), @LF) If @error Then Return SetError(2, 0, 0) Local $sHoldLineNum, $sHoldLineStr For $iCC = 1 To UBound($aSplit) - 1 If StringInStr($aSplit[$iCC], $sFind, $iCase) Then $sHoldLineNum &= $iCC & Chr(1) $sHoldLineStr &= $aSplit[$iCC] & Chr(1) EndIf Next If Not $sHoldLineNum Then Return SetError(3, 0, '') $sHoldLineNum = StringSplit(StringTrimRight($sHoldLineNum, 1), Chr(1)) $sHoldLineStr = StringSplit(StringTrimRight($sHoldLineStr, 1), Chr(1)) Local $aReturnArray[UBound($sHoldLineNum)][2] $aReturnArray[0][0] = UBound($sHoldLineNum) - 1 For $iCC = 1 To UBound($sHoldLineNum) - 1 $aReturnArray[$iCC][0] = $sHoldLineNum[$iCC] $aReturnArray[$iCC][1] = $sHoldLineStr[$iCC] Next Return $aReturnArray EndFunc Func _ArrayDisplay2D($aArray, $sTitle = 'Array Display 2Dim', $iBase = 1, $sToConsole = 0) If Not IsArray($aArray) Then Return SetError(1, 0, 0) Local $sHold = 'Dimension 1 Has: ' & UBound($aArray, 1) -1 & ' Element(s)' & @LF & _ 'Dimension 2 Has: ' & UBound($aArray, 2) - 1 & ' Element(s)' & @LF & @LF For $iCC = $iBase To UBound($aArray, 1) - 1 For $xCC = 0 To UBound($aArray, 2) - 1 $sHold &= '[' & $iCC & '][' & $xCC & '] = ' & $aArray[$iCC][$xCC] & @LF Next Next If $sToConsole Then Return ConsoleWrite(@LF & $sHold) Return MsgBox(262144, $sTitle, StringTrimRight($sHold, 1)) EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
BrettF Posted January 15, 2007 Author Share Posted January 15, 2007 Thanks. I'll see wich one works way works best and which one is the simpilist to read (so i understand it ) Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
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