xtreempje Posted March 20, 2023 Share Posted March 20, 2023 (edited) Currently I have $open = fileopen(@ScriptDir&"\test.txt", 0) $read = fileread($open) $text = $read msgBox(0, "", StringBetween($text, "", ":")) Func StringBetween($sString, $sStart, $sEnd) Local $sReturn $sReturn = _StringBetween($sString, $sStart, $sEnd) If @error Then Return '' Return $sReturn[0] EndFunc But this only read 1 line of the file, I need it to read all lines. I only want to select the IP addresses The file : 125.199.15.243:12324:username:password 275.111.175.243:12324:username:password 785.122.125.243:12324:username:password 385.166.115.243:12324:username:password 485.144.165.243:12324:username:password hope someone can help me out. Edited March 20, 2023 by xtreempje Link to comment Share on other sites More sharing options...
Developers Jos Posted March 20, 2023 Developers Share Posted March 20, 2023 an example input test.txt and what you would expect retuned by the script would help to help you. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
xtreempje Posted March 20, 2023 Author Share Posted March 20, 2023 Just added the test.txt and more info. I only want it to select the IP addresses, so thats everything before the : (colon) Link to comment Share on other sites More sharing options...
Nine Posted March 20, 2023 Share Posted March 20, 2023 Try this : #include <Array.au3> #include <Constants.au3> Local $sFile = _ "125.199.15.243:12324:username:password" & @CRLF & _ "275.111.175.243:12324:username:password" & @CRLF & _ "785.122.125.243:12324:username:password" & @CRLF & _ "385.166.115.243:12324:username:password" & @CRLF & _ "485.144.165.243:12324:username:password" Local $aResult = StringRegExp($sFile, ":(.*?):", $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($aResult) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
xtreempje Posted March 20, 2023 Author Share Posted March 20, 2023 This only display the ports. Thanks for helping tho! Link to comment Share on other sites More sharing options...
Developers Jos Posted March 20, 2023 Developers Share Posted March 20, 2023 (edited) Like this? #include <Array.au3> #include <Constants.au3> Local $sFile = _ "125.199.15.243:12324:username:password" & @CRLF & _ "275.111.175.243:12324:username:password" & @CRLF & _ "785.122.125.243:12324:username:password" & @CRLF & _ "385.166.115.243:12324:username:password" & @CRLF & _ "485.144.165.243:12324:username:password" Local $aResult = StringRegExp($sFile, "(.*?):.*:", $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($aResult) or when it the start of each line until ":": Local $aResult = StringRegExp($sFile, "(?m)^(.*?):", $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($aResult) Edited March 20, 2023 by Jos Dan_555 and pixelsearch 2 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
xtreempje Posted March 20, 2023 Author Share Posted March 20, 2023 Hey thanks man that works! now I gotta find out how to save the array to a txt file. thanks alot! Link to comment Share on other sites More sharing options...
Dan_555 Posted March 20, 2023 Share Posted March 20, 2023 Here is my try to this, a bit longer than with regexp but ... expandcollapse popup#include <Array.au3> #include <Constants.au3> #include <String.au3> Local $sFile = _ "125.199.15.243:12324:username:password" & @CRLF & _ "275.111.175.243:12324:username:password" & @CRLF & _ "785.122.125.243:12324:username:password" & @CRLF & _ "385.166.115.243:12324:username:password" & @CRLF & _ "485.144.165.243:12324:username:password" Local $aSplit=_StringExplode($sFile,@crlf) ;_ArrayDisplay($aSplit) For $x=0 to UBound($aSplit)-1 ConsoleWrite ("Searching nr:" & $x & " : " & $aSplit[$x] & @crlf) $ip=_StringSearchSplit($aSplit[$x],":","L","L") CW($ip) $tmp=_StringSearchSplit($aSplit[$x],":","L","R") $port=_StringSearchSplit($tmp,":","L","L") CW($port) $tmp1=_StringSearchSplit(StringMid($tmp,StringInStr($tmp,":",0,1)),":","L","R") $Username=_StringSearchSplit($tmp1,":","L","L") $Password=_StringSearchSplit($tmp1,":","L","R") Cw($Username) CW($Password) Next Func CW($txt) ConsoleWrite ($txt & @CRLF) EndFunc Func _StringSearchSplit($str, $delimiter, $dir = "L", $ret = "R", $incdel = -1) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringSearchSplit ; Description ...: Search for the first delimiter in a string, with searching direction, Case Sensitive search ; Syntax ........: _StringSearchSplit( $String, $delimiter [, $dir ] [, $ret ] [, $incdel ]) ; Parameters ....: $String - String to be checked. ; $delimiter - 1 char delimiter, has to be defined ; $dir - Search from direction (Left/Right), use "L" or "R" - Left is default ; The first letter will be used for direction, if multiple letters are entered e.g "Lab" = "L" ; $ret - Return side, Left or Right - Right is default. see above for valid entries. ; $incdel - Include delimiter 0 = No, 1 = Yes ; ; Return values .: Success - String ; ; e.g. 1: _StringSearch("c:\bat\test.bb","\","L","L") returns "c:" ; e.g. 2: _StringSearch("c:\bat\test.bb","\","L","L",1) returns "c:\" ; e.g. 3: _StringSearch("c:\bat\test.bb","\","L","R") returns "bat\test.bb" ; e.g. 4: _StringSearch("c:\bat\test.bb","\","L","R",1) returns "\bat\test.bb" ; e.g. 5: _StringSearch("c:\bat\test.bb","\","R","R") returns "test.bb" ; e.g. 6: _StringSearch("c:\bat\test.bb","\","R","R",1) returns "\test.bb" ; ; Failure - Empty string and @error flag as follows: ; @error : 1 - Empty String ; 2 - Delimiter should have a length of 1 char ; 3 - Should not happen, but if it does, search the PANIC button ! ; Author ........: Dan_555 (Autoitscript.com forum) ; =============================================================================================================================== Local $y Local $tmptxt = "" $dir = StringLeft(StringUpper($dir),1) $ret = StringLeft(StringUpper($ret),1) SetError(0) If StringLen($str) = 0 Then SetError(1) ;empty string Return "" EndIf If (StringInStr($str, $delimiter) = 0) Or (StringLen($delimiter) <> 1) Then SetError(2) ;invalid delimiter Return "" EndIf If $dir <> "L" And $dir <> "R" Then $dir = "L" ;Set default values If $ret <> "L" And $ret <> "R" Then $ret = "R" If $dir = "L" Then $y = StringInStr($str, $delimiter, 1) ;Search for the delimiter If $dir = "R" Then $y = StringInStr($str, $delimiter, 1, -1) If $incdel = 0 Then $incdel = -1 ;Tricky calculations ;) If $incdel <> -1 Then $incdel = 0 If $ret = "L" Then Return StringMid($str, 1, $y + $incdel) ;DisAssemble the string If $ret = "R" Then Return StringMid($str, $y - $incdel) SetError (3) Return "" EndFunc ;==>_StringSearchSplit Some of my script sourcecode Link to comment Share on other sites More sharing options...
Developers Jos Posted March 20, 2023 Developers Share Posted March 20, 2023 (edited) 33 minutes ago, xtreempje said: now I gotta find out how to save the array to a txt file. One line should do it: #include <File.au3> _FileWriteFromArray("Testout.txt",$aResult) ;-or- FileWrite("Testout.txt",_ArrayToString($aResult,@crlf)) Edited March 20, 2023 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
xtreempje Posted March 20, 2023 Author Share Posted March 20, 2023 Hey thank you so much guys this solved my issue 🤩 Link to comment Share on other sites More sharing options...
xtreempje Posted March 20, 2023 Author Share Posted March 20, 2023 I got 1 more question. I have made an GUI and in the GUI I open another .au3 script with a gui and when I click save in that new opened gui it saves the .ini file in the folder were the first .au3 script is located instead of where the second one is located /extra ( folder ). this is how it saves the ini Local $sFile = GUICtrlRead($Edit1) Local $hFile = FileOpen($sFile, $FO_OVERWRITE) Local $aResult = StringRegExp($sFile, "(.*?):.*:", $STR_REGEXPARRAYGLOBALMATCH) Filedelete(@ScriptDir & "Testout.ini") Filewrite(@ScriptDir & "Testout.ini", "[Config]" & @crlf) Filewrite(@ScriptDir & "Testout.ini", "edit2=") FileWrite(@ScriptDir & "Testout.ini",_ArrayToString($aResult, "@R@", @crlf)) but now it names it : ExtraTestout instead of Testout. Probl got the ScriptDir wrong I think? Link to comment Share on other sites More sharing options...
Developers Jos Posted March 20, 2023 Developers Share Posted March 20, 2023 (edited) Guess your script directory ends with "\extra"... that should be a good hint. EDIT: And what should this part do in your code: , "@R@", @crlf)) ? Edited March 20, 2023 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
xtreempje Posted March 20, 2023 Author Share Posted March 20, 2023 (edited) Oh its so another edit box opens the file. and thanks man! fixed it. apriciate the help Local $Filelocation = FileOpen( @ScriptDir & "\Testout.ini", 2) that made it work ^^ just messing around alot to learn something Edited March 20, 2023 by xtreempje Link to comment Share on other sites More sharing options...
Developers Jos Posted March 20, 2023 Developers Share Posted March 20, 2023 That's the way learning works! Have you seen my EDIT? Think that third parameter shouldn't be there as you replaced it with the second parameter value. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
xtreempje Posted March 20, 2023 Author Share Posted March 20, 2023 Oh yea let me fix that, thanks! 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