jjohn Posted April 26, 2017 Posted April 26, 2017 Hi all, I have the following code, basically, it populates an array with unique characters found in a string, but it turns out only one character is in the array, i don't want to think it is due to a bug of autoit at this point, so i need your help on why, please Dim $sx[0] Dim $cn $ss = "Xx" ConsoleWrite(StringLeft($ss, 1) & " " & StringRight($ss, 1) & @CRLF) ConsoleWrite(StringLeft($ss, 1) = StringRight($ss, 1) & @CRLF) ;here show X <> x ConsoleWrite(@CRLF) ;the following is to populate array $sx with different unique characters in $ss For $b = 1 To StringLen($ss) $flg = 0 For $a = 0 To UBound($sx) - 1 ;if asc(StringMid($ss,$b,1)) = asc($sx[$a]) Then ;if this line is used instead of the next, everything is fine If StringMid($ss, $b, 1) = $sx[$a] Then If StringMid($ss, $b, 1) = "x" Then ConsoleWrite("<<->>" & StringMid($ss, $b, 1) & " " & $sx[$a] & @CRLF) $flg = 1 ExitLoop EndIf Next If $flg = 0 Then $cn = $cn + 1 ReDim $sx[$cn] $sx[$cn - 1] = StringMid($ss, $b, 1) EndIf Next ConsoleWrite(UBound($sx) & @CRLF);list the ubound of $sx ;list what is in array $sx For $a = 0 To UBound($sx) - 1 ConsoleWrite($sx[$a] & @CRLF) Next same code in a file is attached as uniqueChar2Array.au3
jchd Posted April 26, 2017 Posted April 26, 2017 When applied to strings, = performs a case-insensitive comparison. Use == instead. Skysnake 1 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)
MagnumXL Posted April 26, 2017 Posted April 26, 2017 In the string provided, "Xx" there is only one unique character. Try using StringInStr or StringRegExp to match by case as well.
jjohn Posted April 26, 2017 Author Posted April 26, 2017 Wow, you guys are fast, i learn more today, thanks!
jguinch Posted April 26, 2017 Posted April 26, 2017 (edited) You can also retrieve all uniq characters using a regex : #Include <Array.au3> Local $sString = "This is a complex String" Local $aUniqChars = StringRegExp($sString, "(.)(?!.*\1)", 3) ConsoleWrite(UBound($aUniqChars) & " uniq characters found : " & @CRLF) For $i = 0 To UBound($aUniqChars) - 1 ConsoleWrite( " " & $aUniqChars[$i] & @CRLF) Next or with other basic functions : #include <StringConstants.au3> #Include <Array.au3> Local $sString = "This is a complex String" Local $aChars = StringSplit($sString, "", $STR_NOCOUNT) $aUniqChars = _ArrayUnique($aChars) _ArrayDisplay($aUniqChars) Edited April 26, 2017 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
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