Mumms Posted June 6, 2010 Posted June 6, 2010 (edited) So here is what I want to do: I get the postion of the string in the string I search. (StringInStr) I want to go to the left of that substring until I get to the next ^7 Then I want to get the string that is inbetween the two "^7" Here is what I have so far: FileGetTime($file) If Not @error Then FileOpen($file, 0) $line = FileReadLine($file, -1) $wik = StringInStr($line, "^7 was shot by " & $User, 2) If $wik > 1 Then ;####This is where I need help :p#### Sleep(2500) EndIf Sorry if this doesn't make much sense. *Edit I added this hopefully to explain more* ^7mixx^7 was shot by Mumms ~> This is an example of a line in the file im reading Mumms = $User in script So lets say that the return value for $wik was 10. I want to go left until the next ^7 so that would be 4? And then i want to stringsplit or something so that I only get: "mixx" Edited June 6, 2010 by Mumms
Zibit Posted June 6, 2010 Posted June 6, 2010 try to use stringsplit... wait gonna make an example.. Creator Of Xtreme DevelopersPixel Pattern UDFTray GUI UDFMathssend & recive register scriptMouse Control via Webcam
Zibit Posted June 6, 2010 Posted June 6, 2010 (edited) FileGetTime($file) If Not @error Then FileOpen($file, 0) $line = FileReadLine($file, -1) $wik = StringSplit($line, "^7", 1) $mixx = $wik[2] If $mixx > 1 Then msgbox(0, "", $mixx) Sleep(2500) EndIf Edited June 6, 2010 by Zibit Creator Of Xtreme DevelopersPixel Pattern UDFTray GUI UDFMathssend & recive register scriptMouse Control via Webcam
Yoriz Posted June 6, 2010 Posted June 6, 2010 $sText1 = "^7mixx^7 was shot by Mumms" MsgBox(0, "Result", _StringBetween7n7($sText1)) Func _StringBetween7n7($sText) Local $sLeft = StringTrimLeft($sText, StringInStr($sText, "^7")+1) Return StringLeft($sLeft, StringInStr($sLeft, "^7")-1) EndFunc GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Zibit Posted June 6, 2010 Posted June 6, 2010 great... better one Creator Of Xtreme DevelopersPixel Pattern UDFTray GUI UDFMathssend & recive register scriptMouse Control via Webcam
Mumms Posted June 10, 2010 Author Posted June 10, 2010 (edited) Thanks for all the help, but Its not quite what I'm looking for. Sure your code works when you know what the Text is. But this is a log file so I don't always know what "mixx" would be. So here is what i want to do. I want to get a returned string that is from the first ^7 to the left of "^7 was shot by Mumms" so for example this is what it would say in the log file. "^7Some Name Here^7was shot by Mumms" So i want it to return "^7Some Name Here" So im searching for "^7was shot by Mumms" in the log file and then i need to go to the left until the next ^7 and then get that string that is inbetween those two spots. Sorry I don't know how to explain this properly, So im trying to make it as simple as possible. Thanks again! Edited June 10, 2010 by Mumms
sahsanu Posted June 10, 2010 Posted June 10, 2010 On 6/10/2010 at 6:57 AM, 'Mumms said: Thanks for all the help, but Its not quite what I'm looking for. Sure your code works when you know what the Text is. But this is a log file so I don't always know what "mixx" would be. So here is what i want to do. I want to get a returned string that is from the first ^7 to the left of "^7 was shot by Mumms" so for example this is what it would say in the log file. "^7Some Name Here^7was shot by Mumms" So i want it to return "^7Some Name Here" So im searching for "^7was shot by Mumms" in the log file and then i need to go to the left until the next ^7 and then get that string that is inbetween those two spots. I don't really know what you want... maybe this? If $wik > 1 Then $sResult=StringRegExpReplace($line,".*\^7(.*)\^7.+" & $User,"$1",1) ;####This is where I need help :p#### MsgBox(0,"Debug $sResult","$sResult is " & $sResult) Sleep(2500) EndIf Cheers, sahsanu
Xenobiologist Posted June 10, 2010 Posted June 10, 2010 Why not using the udf _StringBetween? Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Malkey Posted June 10, 2010 Posted June 10, 2010 Another maybe what you want. #include <Array.au3> ; To display array only $User = "Mumms" ;$sFileContents = FileRead("FileFullPath_Name.ext") ; or $sFileContents = "^7mixx & Sons ^7 was shot by Bumms" & @CRLF & _ "Next one ^7mixx^7 was shot by Momms. Another ^7Name^7 was shot by Mumms," & @CRLF & _ "and, Another^7Some Name Here^7was shot by Mumms" $aArray = StringRegExp($sFileContents, "\^7([^^]*?)\^7\h*was shot by " & $User, 3) If IsArray($aArray) Then _ArrayDisplay($aArray) Else MsgBox(0, "Result", "No Matches") EndIf
Yoriz Posted June 10, 2010 Posted June 10, 2010 On 6/10/2010 at 6:57 AM, 'Mumms said: Thanks for all the help, but Its not quite what I'm looking for. Sure your code works when you know what the Text is. But this is a log file so I don't always know what "mixx" would be. Did you try using the scripts posted with other text strings from your log file, you'll find that they dont just search for "mixx". we dont have your log file so the only way we can try what your asking is if you where to post more examples of what the log file could contain and the outcome you want from it. I expect all the scripts posted already probably come close to what you want. If you pass some more text strings to my script you'll see it returns the text it finds between the first and second ^7. $sText1 = "^7mixx^7 was shot by Mumms" MsgBox(0, "Result", _StringBetween7n7($sText1)) ; returns 'mixx' $sText2 = "^7Some Name Here^7was shot by Mumms" MsgBox(0, "Result", _StringBetween7n7($sText2)) ; returns 'Some Name Here' $sText3 = "^7 to the left of ^7 was shot by Mumms" MsgBox(0, "Result", _StringBetween7n7($sText3)); returns ' to the left of ' Func _StringBetween7n7($sText) Local $sLeft = StringTrimLeft($sText, StringInStr($sText, "^7")+1) Return StringLeft($sLeft, StringInStr($sLeft, "^7")-1) EndFunc Try some of the examples using the text from your log file then decide if they dont do what you want on a certain string post it here so the scripts can be adjusted to suit your needs. GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Mumms Posted June 12, 2010 Author Posted June 12, 2010 @sahsanu Thank you so much! your script worked perfectly. Can you explain how you made the pattern work though? @everyone else Thank you very much for posting. Your scripts have gave me new ideas that I will most likely use! Once again thanks for the help
sahsanu Posted June 12, 2010 Posted June 12, 2010 On 6/12/2010 at 1:41 AM, 'Mumms said: @sahsanu Thank you so much! your script worked perfectly. Can you explain how you made the pattern work though? You are welcome, I'm happy to see it worked for you. The pattern is .*\^7(.*)\^7.+$User but I think that should be better to place $User variable between \Q...\E so the username name will be escaped. It should be: .*\^7(.*)\^7.+\Q$User\E and in your script: If $wik > 1 Then $sResult=StringRegExpReplace($line,".*\^7(.*)\^7.+\Q" & $User & "\E","$1",1) ;####This is where I need help :p#### MsgBox(0,"Debug $sResult","$sResult is " & $sResult) Sleep(2500) EndIf And this is the explanation: «.*» Match any single character that is not a line break character «\^» Match the character “^” literally «7» Match the character “7” literally «(.*)» Match the regular expression below and capture its match into backreference number 1 «.*» Match any single character that is not a line break character «\^» Match the character “^” literally «7» Match the character “7” literally «.+» Match any single character that is not a line break character «\Q» Begin \Q..\E escape sequence $User Match the characters in the variable $User literally «\E» End \Q..\E escape sequence Have a nice day. sahsanu
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