Sobiech Posted May 26, 2010 Share Posted May 26, 2010 Func _GetStrline($path, $text) For $i = 1 To _FileCountLines($path) Step +1 If FileReadLine ($path, $i) = $text Then $line = $i ExitLoop EndIf Next return $line EndFunc I think this should work, but i have small problem with this eg. line from test.txt jabadaba and my scripts wont work if i write _GetStrLine("test.txt", "jaba") because he fail if my line dont have spaces how to set this to something like that? _GetStrLine("test.txt", "*.*" & "jaba" & "*.*") This world is crazy Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 26, 2010 Share Posted May 26, 2010 StringInStr()? .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 26, 2010 Share Posted May 26, 2010 StringInStr() 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 Link to comment Share on other sites More sharing options...
Sobiech Posted May 26, 2010 Author Share Posted May 26, 2010 ok ok stop ^^ Thx i will look at this func This world is crazy Link to comment Share on other sites More sharing options...
AlmarM Posted May 26, 2010 Share Posted May 26, 2010 (edited) Something like this? expandcollapse popupLocal $Path = @ScriptDir & "\get_string_number.txt" Local $String = Random(0, 50, 1) For $i = 0 To 50 FileWrite($Path, $i & @CRLF) Next $TestFunc = _GetStringLineNumber($String, $Path) If $TestFunc = 0 Then MsgBox(0, "", "No results found.") Else MsgBox(0, "", "String '" & $String & "' was found on linenumber: " & $TestFunc) EndIf Func _GetStringLineNumber($sString, $sFile, $iCase = 0) Local $iLineNumber = 0 $hOpen = FileOpen($sFile, 0) $sRead = FileRead($hOpen) $aSplit = StringSplit($sRead, Chr(10)) For $i = 1 To $aSplit[0] $iLineNumber += 1 $sReadLine = FileReadLine($hOpen, $i) If $iCase = 0 Then If $sReadLine = $sString Then FileClose($hOpen) Return $iLineNumber EndIf EndIf If $iCase = 1 Then If $sReadLine == $sString Then FileClose($hOpen) Return $iLineNumber EndIf EndIf Next Return 0 EndFunc EDIT: Wait, I missed something. :/ Nevermind this. Edited May 26, 2010 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Sobiech Posted May 26, 2010 Author Share Posted May 26, 2010 Yes, but this wont show me substring I will edit this This world is crazy Link to comment Share on other sites More sharing options...
AlmarM Posted May 26, 2010 Share Posted May 26, 2010 (edited) Yes, but this wont show me substring I will edit this Substring? EDIT: Just noticed I dont need any $iLineNumber expandcollapse popupLocal $Path = @ScriptDir & "\get_string_number.txt" Local $String = Random(0, 50, 1) For $i = 0 To 50 FileWrite($Path, $i & @CRLF) Next $TestFunc = _GetStringLineNumber($String, $Path) If $TestFunc = 0 Then MsgBox(0, "", "No results found.") Else MsgBox(0, "", "String '" & $String & "' was found on linenumber: " & $TestFunc) EndIf Func _GetStringLineNumber($sString, $sFile, $iCase = 0) $hOpen = FileOpen($sFile, 0) $sRead = FileRead($hOpen) $aSplit = StringSplit($sRead, Chr(10)) For $i = 1 To $aSplit[0] $sReadLine = FileReadLine($hOpen, $i) If $iCase = 0 Then If $sReadLine = $sString Then FileClose($hOpen) Return $i EndIf EndIf If $iCase = 1 Then If $sReadLine == $sString Then FileClose($hOpen) Return $i EndIf EndIf Next Return 0 EndFunc Still, what do you mean by substring? Edited May 26, 2010 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Sobiech Posted May 26, 2010 Author Share Posted May 26, 2010 (edited) Substring? If $sReadLine = StringInStr($sReadLine, $sString) Then Hmmm whats wrong? Substring is a "234" in eg. "12345" Edited May 26, 2010 by Sobiech This world is crazy Link to comment Share on other sites More sharing options...
AlmarM Posted May 26, 2010 Share Posted May 26, 2010 If $sReadLine = StringInStr($sReadLine, $sString) Then Hmmm whats wrong? Substring is a "234" in eg. "12345" Ah so, hold on. *Writes* Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
GEOSoft Posted May 26, 2010 Share Posted May 26, 2010 (edited) If StringInStr($sReadLine, %sString) Then If you would post a few lines of what the file contains and what you actually want returned from the example, it would help others help you. EDIT: It is probably just a simple StringRegExp() or StringRegExpReplace() that you need but without seeing an example we can't tell you for sure. Edited May 26, 2010 by GEOSoft 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...
PsaltyDS Posted May 26, 2010 Share Posted May 26, 2010 StringInStr() returns the integer location where the search string was found: $sString = "jabadaba" $iVal = StringInStr($sString, "jaba") ConsoleWrite("$iVal = " & $iVal & @LF) $iVal = StringInStr($sString, "daba") ConsoleWrite("$iVal = " & $iVal & @LF) $iVal = StringInStr($sString, "wxyz") ConsoleWrite("$iVal = " & $iVal & @LF) 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 Link to comment Share on other sites More sharing options...
AlmarM Posted May 26, 2010 Share Posted May 26, 2010 expandcollapse popupLocal $Path = @ScriptDir & "\get_string_number.txt" Local $String = "," FileWrite($Path, "t13est" & @CRLF) FileWrite($Path, "test2" & @CRLF) FileWrite($Path, "te131st3" & @CRLF) FileWrite($Path, "test65" & @CRLF) FileWrite($Path, "tes43thihi" & @CRLF) FileWrite($Path, "tesst" & @CRLF) FileWrite($Path, "te,stad" & @CRLF) FileWrite($Path, "te4st" & @CRLF) FileWrite($Path, "tes35sdt" & @CRLF) FileWrite($Path, "tes1231t" & @CRLF) $TestFunc = _GetStringLineNumber($String, $Path) If $TestFunc = 0 Then MsgBox(0, "", "No results found.") Else MsgBox(0, "", "String '" & $String & "' was found on linenumber: " & $TestFunc) EndIf Func _GetStringLineNumber($sString, $sFile, $iCase = 0) $hOpen = FileOpen($sFile, 0) $sRead = FileRead($hOpen) $aSplit = StringSplit($sRead, Chr(10)) For $i = 1 To $aSplit[0] $sReadLine = FileReadLine($hOpen, $i) If $iCase = 0 Then If $sReadLine = $sString Or StringInStr($sReadLine, $sString) Then FileClose($hOpen) Return $i EndIf EndIf If $iCase = 1 Then If $sReadLine == $sString Or StringInStr($sReadLine, $sString)Then FileClose($hOpen) Return $i EndIf EndIf Next Return 0 EndFunc Like this? Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Sobiech Posted May 26, 2010 Author Share Posted May 26, 2010 Perfect work! Thx for all i love you This world is crazy Link to comment Share on other sites More sharing options...
AlmarM Posted May 26, 2010 Share Posted May 26, 2010 No problem Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. 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