VinMe Posted February 19, 2020 Posted February 19, 2020 HELLO All, is there any function in Auto it to Remove the repeating strings separated by "," which is present in the array. ex. Available state a[0]= D97,D96,,D85,D86,D85,D86,D85,D86,D85,,D86,D85,D86,D85,D86 a[1]=D85,D24,,,,,D85 Required state a[0]= D97,D96,D85,D86, a[1]=D85,D24 thank you in advance! vin!
Musashi Posted February 19, 2020 Posted February 19, 2020 #include <StringConstants.au3> #include <Array.au3> Global $g_sString, $g_sOutput $g_sString = "D97,D96,,D85,D86,D85,D86,D85,D86,D85,,D86,D85,D86,D85,D86" ; remove duplicates : $g_sOutput = _ArrayToString(_ArrayUnique(StringSplit($g_sString, ",", $STR_NOCOUNT), 0, 0, 0, $ARRAYUNIQUE_NOCOUNT), ",") ConsoleWrite('> >>> String Output = ' & $g_sOutput & @CRLF) "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Moderators JLogan3o13 Posted February 19, 2020 Moderators Posted February 19, 2020 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
jchd Posted February 19, 2020 Posted February 19, 2020 Another way: Local $sString = "D97,D96,,D85,D86,D85,D86,D85,D86,D85,,D86,D98,D85,D86,D85,D86" ; remove duplicates : Local $sOutput = StringRegExpReplace(StringRegExpReplace($sString, "(\b\w+\b,?)(?=.*?\1)", ""), ",+", ",") ConsoleWrite($sString & @LF & $sOutput & @LF) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Malkey Posted February 20, 2020 Posted February 20, 2020 (edited) Another example. #include <Debug.au3>; Included For _DebugArrayDisplay() use only. ; https://www.autoitscript.com/forum/topic/201783-unique-elements-in-array-moved/?do=findComment&comment=1447861 Local $a[3] = [ _ "D97,,,D96,D85,D85,D86,,D8!6,D85,D8!6,,CD85,,D86,D98,,,,,D85,D86,CD85,,D86", _ ",,D85,D24,,,,,D85", _ "D85,D24,,,,,,D85,,"] For $i = 0 To UBound($a) - 1 ; Remove duplicate elements; Remove leading and trailing commas; Remove all the commas followed by a comma (one comma remains from a whole group of commas). ;$a[$i] = StringRegExpReplace($a[$i], "(\b\w+\b),*(?=.*?\1)|(^,+|,+$)|,+(?=,)", "") ; Overcomes "\b" problem by matching non-word characters embedded in the comma separated "test" string. ;$a[$i] = StringRegExpReplace($a[$i], "((?<=,|^)[^,]+(?=,)),*(?=.*?\1)|(^,+|,+$)|,+(?=,)", "") ; This latest RE example overcomes the error of the missing "D85" because "D85" mistakenly matched "CD85". $a[$i] = StringRegExpReplace($a[$i], "((?<=^|,)[^,]+(?=,)),*(?=.*?,\1,?)|(^,+|,+$)|,+(?=,)", "") ; <----------- The working Reg. Exp. Next _DebugArrayDisplay($a) Edited February 24, 2020 by Malkey I thought mikell's following example was the way to go. But now, I managed to overcome the problem that using "\b" created.
mikell Posted February 20, 2020 Posted February 20, 2020 and another one #include <Array.au3> Local $sString = "D97,D96,,D85,D86,D85,D86,D85,D86,D85,,D86,D98,D85,D86,D85,D86" Local $a = StringSplit($sString, ","), $sda = ObjCreate("Scripting.Dictionary") For $i = 1 to $a[0] If $a[$i] Then $sda.Item($a[$i]) Next $asda = $sda.Keys() ; _ArraySort($asda) _ArrayDisplay($asda)
Deye Posted February 25, 2020 Posted February 25, 2020 (edited) Not as great for long strings, but anyways add in to the mix: Edit: Now as Fast as doing this with Scripting.Dictionary Func StringUnique_Delim($sString = "", $delim = ",") Return StringTrimLeft(StringRegExpReplace($delim & $sString, '(' & $delim & '[^' & $delim & ']+(?=' & $delim & '))(?=.*\1)|' & $delim & '(?=' & $delim & ')', ""), 1) EndFunc ;==>StringUnique_Delim Edited February 26, 2020 by Deye
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