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

Line 756:
"1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ" (Length 36) '0'(0X30) [9, 24]
</pre>
 
=={{header|D}}==
{{trans|C++}}
<lang d>import std.stdio;
 
void uniqueCharacters(string str) {
writefln("input: `%s`, length: %d", str, str.length);
foreach (i; 0 .. str.length) {
foreach (j; i + 1 .. str.length) {
if (str[i] == str[j]) {
writeln("String contains a repeated character.");
writefln("Character '%c' (hex %x) occurs at positions %d and %d.", str[i], str[i], i + 1, j + 1);
writeln;
return;
}
}
}
writeln("String contains no repeated characters.");
writeln;
}
 
void main() {
uniqueCharacters("");
uniqueCharacters(".");
uniqueCharacters("abcABC");
uniqueCharacters("XYZ ZYX");
uniqueCharacters("1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ");
}</lang>
{{out}}
<pre>input: ``, length: 0
String contains no repeated characters.
 
input: `.`, length: 1
String contains no repeated characters.
 
input: `abcABC`, length: 6
String contains no repeated characters.
 
input: `XYZ ZYX`, length: 7
String contains a repeated character.
Character 'X' (hex 58) occurs at positions 1 and 7.
 
input: `1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ`, length: 36
String contains a repeated character.
Character '0' (hex 30) occurs at positions 10 and 25.</pre>
 
=={{header|Factor}}==
1,452

edits