gcue Posted May 19, 2009 Share Posted May 19, 2009 (edited) hello everyone. im trying to find "G283H88620TS" within "MX0G283H7426288620TS" problem is that theres no pattern on where in the string to search for.. as you can see in the case above, G283H...88620TS are in common but not the middle part.. but sometimes there is no middle part.. arrggg what would the syntax look like? thanks! Edited May 19, 2009 by gcue Link to comment Share on other sites More sharing options...
martin Posted May 19, 2009 Share Posted May 19, 2009 hello everyone.im trying to find "G283H88620TS" within "MX0G283H7426288620TS"problem is that theres no pattern on where in the string to search for.. as you can see in the case above, G283H...88620TS are in common but not the middle part..but sometimes there is no middle part.. arrgggwhat would the syntax look like?thanks!StringInStr would be best I think. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
gcue Posted May 19, 2009 Author Share Posted May 19, 2009 hey martin! ya i tried that.. doesnt match up if theres something in the middle. Link to comment Share on other sites More sharing options...
Mat Posted May 19, 2009 Share Posted May 19, 2009 (edited) If StringInStr AND StringInStr AND StringInStr ... etc. as long as its below 4000 chars, you should be able to do it in one line. Or you could be neat and do: MsgBox (0, "", _StringInStrRandom ("MX0G283H7426288620TS", "G283H88620TS")) Func _StringInStrRandom ($sSearchString, $sCharsString) Local $i, $Err = 0, $String = $sCharsString For $i = 1 To StringLen ($sCharsString) If Not (StringInStr ($sSearchString, StringLeft ($String, 1))) Then $Err += 1 $String = StringTrimLeft ($String, 1) Next If $Err = 0 Then Return 1 Return SetError ($Err, 0, 0) EndFunc ; ==> _StringInStrRandom MDiesel Edited May 19, 2009 by mdiesel AutoIt Project Listing Link to comment Share on other sites More sharing options...
martin Posted May 19, 2009 Share Posted May 19, 2009 hey martin!ya i tried that.. doesnt match up if theres something in the middle.Where might the extra characters appear? Could they be anywhere in the string "G283H88620TS", or are you looking for the letters in that string to appear in order anywhere in the other string?For example, would this string contain what you are searching for"£$G{)(2%^^8$£{{3>>:<H@8**8(%620TyytrfS" Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
martin Posted May 19, 2009 Share Posted May 19, 2009 If StringInStr AND StringInStr AND StringInStr ... etc. as long as its below 4000 chars, you should be able to do it in one line. Or you could be neat and do: MsgBox (0, "", _StringInStrRandom ("MX0G283H7426288620TS", "G283H88620TS")) Func _StringInStrRandom ($sSearchString, $sCharsString) Local $i, $Err = 0 For $i = 1 To StringLen ($sCharsString) If Not (StringInStr ($sSearchString, StringLeft ($sCharsString, 1))) Then $Err += 1 StringTrimLeft ($sCharsString, 1) Next If $Err = 0 Then Return 1 Return SetError ($Err, 0, 0) EndFunc ; ==> _StringInStrRandom MDieselThat doesn't look like it checks for the characters in the search string to be in the order they are in $sCharsString, or am I reading it wrong? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
martin Posted May 19, 2009 Share Posted May 19, 2009 Maybe something like this MsgBox (0, "", _StringInStrRandom ("MX0G2H883H7426288620TS", "G283H88620TS")) Func _StringInStrRandom ($sSearchString, $sCharsString) Local $i, $Err = 0 Local $aS=stringsplit($sCharsString,''),$newS for $i = 1 to $aS[0] $newS &= ".*" & $aS[$i] Next $newS &= ".*" ConsoleWrite($newS & @CRLF) return StringRegExp($sSearchString,"(" & $newS & ")") EndFunc; ==> _StringInStrRandom Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Mat Posted May 19, 2009 Share Posted May 19, 2009 (edited) I thought the idea was it could be oin any order... you could do Func _StringInStrRandom2 ($sSearchString, $sCharsString) $sChars = $sCharsString $String = StringSplit ($sSearchString, "") For $i = 1 To $String[0] If $String[$i] = StringLeft ($sChars, 1) Then $sChars = StringTrimLeft ($sChars, 1) Next If StringLen ($sChars) > 0 Then Return SetError (StringLen ($sChars), 0, 0) Return 1 EndFunc ; ==> _StringInStrRandom2 MDiesel Edit: Whilst on this subject, Martin - I believe you posted on how to use stringregexp to find character changes, eg xxxyy would return xxx and yy. I can't seem to find it. Edited May 19, 2009 by mdiesel AutoIt Project Listing Link to comment Share on other sites More sharing options...
martin Posted May 19, 2009 Share Posted May 19, 2009 Edit: Whilst on this subject, Martin - I believe you posted on how to use stringregexp to find character changes, eg xxxyy would return xxx and yy. I can't seem to find it.No, I don't think that was me. It would be more likely that if I did it I would have done some sort of loop, checking the match of the next character and .. well probably I would end up with something similar to the code you posted earlier. SmOke_N is more likely to have done something like that with stringRegExp, but then so are a few hundred others! Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
gcue Posted May 19, 2009 Author Share Posted May 19, 2009 hmm not sure what you mean by any order..actually i think its not working right mdisel (might be the way i explained it)so what im looking for is find stringA within stringBexamples where it should be found:stringB = "JJJJJJAAAAAAAABBBBBBB123"stringA = "AAAAAAAA123" (TRUE)stringA = "123" (FALSE bc it still needs AAAAAAAA)stringA = "A1A2A3AAAA" (FALSE bc stringA should be in the same sequence)stringA never would be out of the same sequence in stringB but there MIGHT be some characters in between stringBhope this makes sense!thanks for your help! Link to comment Share on other sites More sharing options...
gcue Posted May 19, 2009 Author Share Posted May 19, 2009 looks like this is working martin! many many thanks! Maybe something like this MsgBox (0, "", _StringInStrRandom ("MX0G2H883H7426288620TS", "G283H88620TS")) Func _StringInStrRandom ($sSearchString, $sCharsString) Local $i, $Err = 0 Local $aS=stringsplit($sCharsString,''),$newS for $i = 1 to $aS[0] $newS &= ".*" & $aS[$i] Next $newS &= ".*" ConsoleWrite($newS & @CRLF) return StringRegExp($sSearchString,"(" & $newS & ")") EndFunc; ==> _StringInStrRandom Link to comment Share on other sites More sharing options...
oMBRa Posted May 19, 2009 Share Posted May 19, 2009 try this: #include <Array.au3> $String = 'MX0G283H7426288620TS' $a = StringRegExpReplace($String, '(?i)(G283H)(?:.*)(88620TS)', '\1\2') MsgBox(0, '', $a) Link to comment Share on other sites More sharing options...
gcue Posted May 19, 2009 Author Share Posted May 19, 2009 No, I don't think that was me. It would be more likely that if I did it I would have done some sort of loop, checking the match of the next character and .. well probably I would end up with something similar to the code you posted earlier. SmOke_N is more likely to have done something like that with stringRegExp, but then so are a few hundred others!martin,i just need it to be NOT case sensitive.. then it will be perfect! Link to comment Share on other sites More sharing options...
gcue Posted May 19, 2009 Author Share Posted May 19, 2009 ombra, i cant predict when theres going to be chars in the middle or not =/ thanks!! try this: #include <Array.au3> $String = 'MX0G283H7426288620TS' $a = StringRegExpReplace($String, '(?i)(G283H)(?:.*)(88620TS)', '\1\2') MsgBox(0, '', $a) Link to comment Share on other sites More sharing options...
martin Posted May 19, 2009 Share Posted May 19, 2009 martin, i just need it to be NOT case sensitive.. then it will be perfect! I think you just need to change the last line in the function to return StringRegExp($sSearchString,"(?i:" & $newS & ")") Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
oMBRa Posted May 19, 2009 Share Posted May 19, 2009 Martin your code isnt actually founding the chars in the string btw here is my code: $String = 'MX0G283H7426288620TS' $Chars = 'G283H88620TS' MsgBox(0, '', _SearchInString($String, $Chars)) Func _SearchInString($String, $Char) Local $Pattern = '(?i)(?:.*)', $Replace, $nChars, $Result $nChars = StringSplit($Char, '') For $i = 1 To $nChars[0] $Pattern &= '(' & $nChars[$i] & ')(?:.*)' $Replace &= '\' & $i Next $Result = StringRegExpReplace($String, $Pattern, $Replace) Return $Result EndFunc ;==>_SearchInString Link to comment Share on other sites More sharing options...
Aceguy Posted May 19, 2009 Share Posted May 19, 2009 what are you trying to return, if a match is found... #include <Array.au3> $String = 'MX0G283H7426288620tS' $a = StringRegexp($String, '(?i)(g283h).*(88620ts)') if $a=1 then MsgBox(0,"","found both g283h & 88620ts",0) Else MsgBox(0,"","Not found sorry",0) endif [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
oMBRa Posted May 19, 2009 Share Posted May 19, 2009 (edited) what are you trying to return, if a match is found... #include <Array.au3> $String = 'MX0G283H7426288620tS' $a = StringRegexp($String, '(?i)(g283h).*(88620ts)') if $a=1 then MsgBox(0,"","found both g283h & 88620ts",0) Else MsgBox(0,"","Not found sorry",0) endif no you are wrong, $a = the new string EDIT: sorry I read StringRegexpReplace instead of StringRegexp Edited May 19, 2009 by oMBRa Link to comment Share on other sites More sharing options...
Authenticity Posted May 19, 2009 Share Posted May 19, 2009 Almost, on success $a = array type, on failure $a = nothing. Link to comment Share on other sites More sharing options...
oMBRa Posted May 19, 2009 Share Posted May 19, 2009 yes I know, I read wrong, I edited my last post 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