John117 Posted December 14, 2007 Share Posted December 14, 2007 (edited) suppose I have two strings $String1 and $String2 AutoIt$String1 = lksdf123456788888888lkjh $String2 = sdfsesdfesdsd12345kskdp888ofispfi800-oÝ÷ Ø(ºWeG¡Ú,¢g)à)¶¬jëh×6AutoIt$result = StringCompare( $String1, $String2) And have the $result be the largest section that is the sameoÝ÷ Ú'ºÚ"µÍ]]Ò] ÌÍÔÝ[HLÍ Can this be done? and how would it know that '888' that comes later doesn't overrule the first? or what if 888 was longer? would it then overrule the first? Edited December 14, 2007 by Hatcheda Link to comment Share on other sites More sharing options...
John117 Posted December 14, 2007 Author Share Posted December 14, 2007 (edited) the only way that I can think to do this is to take string1 digit by digit and check string2 for that digit. then the digit after string1 digit one against string two . . . then start all over with string 1 digit 2 . . . you guys thinking of anyting faster? since the actual string is hundreds of digits I guess I could start with matches of more than 1 sorry the first post is messy, it breaks when i try to edit it. Edit; on second thought I am thinking work backwards until the first match so that it runs the shortest maybe start with 20 characters? -ofcourse this method would still be really slow. Edited December 14, 2007 by Hatcheda Link to comment Share on other sites More sharing options...
weaponx Posted December 14, 2007 Share Posted December 14, 2007 (edited) Whos your daddy? (Its probably not me unless you are age 10 or under) #include <Array.au3> $String1 = "lksdf123456788888888lkjh" $String2 = "sdfsesdfesdsd12345kskdp888ofispfi800-" $result = StringFindLongestMatch($String1, $String2) MsgBox(0,"",$result);Returns 12345 $String1 = "abcdefghijklmnopqrstuvwxyz" $String2 = "aaaaaaaaaaaajklmnobbbbbbbbbbbbb" $result = StringFindLongestMatch($String1, $String2) MsgBox(0,"",$result) ;Returns jklmno Func StringFindLongestMatch($SFLM1, $SFLM2) $longestMatch = "" $array1 = StringSplit($SFLM1, "") $array2 = StringSplit($SFLM2, "") For $X = 1 to $array1[0] For $Y = $X to $array1[0] $tempString = _ArrayToString ($array1, "", $X, $Y) ConsoleWrite($tempString & @CRLF) If StringInStr($SFLM2,$tempString) AND StringLen ($tempString) > StringLen ($longestMatch ) Then $longestMatch = $tempString Next Next Return $longestMatch EndFunc Edited December 14, 2007 by weaponx Link to comment Share on other sites More sharing options...
Nahuel Posted December 14, 2007 Share Posted December 14, 2007 Haha, that's really brilliant weaponx! I was doing it in a different way but I was stuck! Great job. Link to comment Share on other sites More sharing options...
weaponx Posted December 14, 2007 Share Posted December 14, 2007 Here is another version that doesn't require arrays (eliminating need for Array.au3): Func StringFindLongestMatch2($SFLM1, $SFLM2) $longestMatch = "" For $X = 1 to StringLen ($SFLM1) For $Y = $X to StringLen ($SFLM1) $tempString = StringMid ($SFLM1, $X, $Y - $X) ConsoleWrite($tempString & @CRLF) If StringInStr($SFLM2,$tempString) AND StringLen ($tempString) > StringLen ($longestMatch ) Then $longestMatch = $tempString Next Next Return $longestMatch EndFunc Link to comment Share on other sites More sharing options...
Paulie Posted December 14, 2007 Share Posted December 14, 2007 Whos your daddy? (Its probably not me unless you are age 10 or under)Kudos to you! I was racking my brain to think how to go about that. That was right on the money. Link to comment Share on other sites More sharing options...
John117 Posted December 14, 2007 Author Share Posted December 14, 2007 (edited) ok heres what I have so far: For $i = 1 To 20 $var = StringMid("lksdf123456788888888lkjh", $i, 5) If StringInStr("sdfsesdfesdsd12345kskdp888ofispfi800-", $var) Then MsgBox(0, "", $var) Else ;nothing EndIf Next edit; wow you guys have been busy *reading Edited December 14, 2007 by Hatcheda Link to comment Share on other sites More sharing options...
John117 Posted December 14, 2007 Author Share Posted December 14, 2007 hey yours looks a little better than mine sorry for the long delay in response, trying to think, code, and read while dodging my bouncing 3 year old and attending to my crying 9mth old Thanks a ton! Link to comment Share on other sites More sharing options...
weaponx Posted December 14, 2007 Share Posted December 14, 2007 I love a good puzzle. Those are my favorite kind of programs. Link to comment Share on other sites More sharing options...
Nahuel Posted December 14, 2007 Share Posted December 14, 2007 Me too! And you beat me Haha, mine was a bit longer though :"> Link to comment Share on other sites More sharing options...
John117 Posted December 14, 2007 Author Share Posted December 14, 2007 well, if this is a comp for the longest , im sure mine would have taken days! 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