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

no edit summary
No edit summary
Line 2,679:
The characters in the string aren't all unique.
The character 0 ('30'x) at position 10 is repeated at position 25
</pre>
 
=={{header|Ring}}==
<lang ring>
load "stdlib.ring"
 
inputStr = ["",".","abcABC","XYZ ZYX","1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ"]
 
for n = 1 to len(inputStr)
check = 1
for x = 1 to len(inputStr[n])
for y = x + 1 to len(inputStr[n])
if inputStr[n][x] = inputStr[n][y]
check = 0
char = inputStr[n][x]
see "Input = " + "'" + inputStr[n] + "'" + ", length = " + len(inputStr[n]) + nl
see " First duplicate at positions " + x + " and " + y + ", character = " + "'" + char + "'" + nl
exit 2
ok
next
next
if check = 1
see "Input = " + "'" + inputStr[n] + "'" + ", length = " + len(inputStr[n]) + nl
see " All characters are unique." + nl
ok
next
</lang>
{{out}}
<pre>
Input = '', length = 0
All characters are unique.
Input = '.', length = 1
All characters are unique.
Input = 'abcABC', length = 6
All characters are unique.
Input = 'XYZ ZYX', length = 7
First duplicate at positions 1 and 7, character = 'X'
 
Input = '1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ', length = 36
First duplicate at positions 10 and 25, character = '0'
</pre>
 
2,468

edits