Determine if a string has all unique characters: Difference between revisions

Content added Content deleted
No edit summary
(Added AutoHotkey)
Line 541: Line 541:
'XYZ ZYX' (7) -> 'X' at 1, 7
'XYZ ZYX' (7) -> 'X' at 1, 7
'1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ' (36) -> '0' at 10, 25</pre>
'1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ' (36) -> '0' at 10, 25</pre>

=={{header|AutoHotkey}}==
<lang AutoHotkey>unique_characters(str){
arr := [], res := ""
for i, v in StrSplit(str)
arr[v] := arr[v] ? arr[v] "," i : i
for i, v in Arr
if InStr(v, ",")
res .= v "|" i " @ " v "`tHex = " format("{1:X}", Asc(i)) "`n"
Sort, res, N
res := RegExReplace(res, "`am)^[\d,]+\|")
res := StrSplit(res, "`n").1
return """" str """`tlength = " StrLen(str) "`n" (res ? "Duplicates Found:`n" res : "Unique Characters")
}</lang>
Examples:<lang AutoHotkey>test := ["",".","abcABC","XYZ ZYX","1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ"]
for i, v in test
MsgBox % unique_characters(v)
return</lang>
Outputs:<pre>"" length = 0
Unique Characters
---------------------------
"." length = 1
Unique Characters
---------------------------
"abcABC" length = 6
Duplicates Found:
a @ 1,4 Hex = 61
---------------------------
"XYZ ZYX" length = 7
Duplicates Found:
X @ 1,7 Hex = 58
---------------------------
"1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ" length = 36
Duplicates Found:
0 @ 10,25 Hex = 30
---------------------------</pre>



=={{header|AWK}}==
=={{header|AWK}}==