Datenshi Posted September 4, 2009 Posted September 4, 2009 (edited) Don't know if this already existed but i couldn't find it so, i just made my own function. Should be included to the String UDF. I'm sure it can be made a bit better and some error checking is still missing, but I'll fix that if people would like this to be included or not. ; #FUNCTION# ;=============================================================================== ; ; Name...........: _StringDiff ; Description ...: Returns the difference between 2 strings, expressed in the type requested ; Syntax.........: _StringDiff($sFirst,$sSecond[,$iStart = 1][,$iReturn = 0]) ; Parameters ....: $sFirst - First String ; $sSecond - String to match to $sFirst, this is the string which is checked for differences. ; $iReturn - One of the following: ; |0 - Returns character that differs (Default) ; |1 - Returns position of character that differs ; $iStart - Where to start matching in the first string ; |1 to max length of first string. See StringMid() in help ; Return values .: Success - Returns first found difference between 2 strings, ; |either position or char depending on $iReturn ; Failure - Returns 0 and Sets @Error: ; |0 - No error. ; |1 - Start pos higher/lower then string length. ; |2 - No Difference found. ; Author ........: Emanuel "Datenshi" Lindgren ; Example .......; No ; ; ;========================================================================================== Func _StringDiff($sFirst, $sSecond, $iStart = 1, $iReturn = 0) If StringLen($sFirst) < $iStart Or $iStart < 1 Then SetError(1) For $i = $iStart To StringLen($sFirst) If StringMid($sFirst, $i, 1) <> StringMid($sSecond, $i, 1) Then Switch $iReturn Case 0 Return StringMid($sSecond, $i, 1) Case 1 Return $i EndSwitch EndIf Next SetError(2) EndFunc ;==>_StringDiff_StringDiff.au3 Edited September 5, 2009 by Datenshi RapidQueuer 2.4 - For Rapidshare.comOpensubtitles Hashing FuncRevision3 PlayerGTPlayer BetaIMDB & Poster Grabber v1.3Fetgrek.com - My Website
WideBoyDixon Posted September 17, 2009 Posted September 17, 2009 If might be more useful to compare the strings for how similar they are e.g. "stationary" and "stationery". See my original post here: http://www.autoitscript.com/forum/index.php?showtopic=40843&view=findpost&p=642358 for an implementation of Levenshtein. WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center]
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