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

no edit summary
No edit summary
No edit summary
Line 3,815:
'XYZ ZYX' (Length 7) 'X' (0X58)[0, 6], 'Y' (0X59)[1, 5], 'Z' (0X5A)[2, 4]
'1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ' (Length 36) '0' (0X30)[9, 24]</pre>
 
=={{header|Vlang}}==
{{trans|go}}
<lang vlang>fn analyze(s string) {
chars := s.runes()
le := chars.len
println("Analyzing $s which has a length of $le:")
if le > 1 {
for i := 0; i < le-1; i++ {
for j := i + 1; j < le; j++ {
if chars[j] == chars[i] {
println(" Not all characters in the string are unique.")
println(" '${chars[i]}'' (0x${chars[i]:x}) is duplicated at positions ${i+1} and ${j+1}.\n")
return
}
}
}
}
println(" All characters in the string are unique.\n")
}
fn main() {
strings := [
"",
".",
"abcABC",
"XYZ ZYX",
"1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ",
"01234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ0X",
"hétérogénéité",
"🎆🎃🎇🎈",
"😍😀🙌💃😍🙌",
"🐠🐟🐡🦈🐬🐳🐋🐡",
]
for s in strings {
analyze(s)
}
}</lang>
 
{{out}}
<pre>
Analyzing which has a length of 0:
All characters in the string are unique.
 
Analyzing . which has a length of 1:
All characters in the string are unique.
 
Analyzing abcABC which has a length of 6:
All characters in the string are unique.
 
Analyzing XYZ ZYX which has a length of 7:
Not all characters in the string are unique.
'X'' (0x58) is duplicated at positions 1 and 7.
 
Analyzing 1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ which has a length of 36:
Not all characters in the string are unique.
'0'' (0x30) is duplicated at positions 10 and 25.
 
Analyzing 01234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ0X which has a length of 39:
Not all characters in the string are unique.
'0'' (0x30) is duplicated at positions 1 and 11.
 
Analyzing hétérogénéité which has a length of 13:
Not all characters in the string are unique.
'é'' (0xe9) is duplicated at positions 2 and 4.
 
Analyzing 🎆🎃🎇🎈 which has a length of 4:
All characters in the string are unique.
 
Analyzing 😍😀🙌💃😍🙌 which has a length of 6:
Not all characters in the string are unique.
'😍'' (0x1f60d) is duplicated at positions 1 and 5.
 
Analyzing 🐠🐟🐡🦈🐬🐳🐋🐡 which has a length of 8:
Not all characters in the string are unique.
'🐡'' (0x1f421) is duplicated at positions 3 and 8.
</pre>
 
=={{header|Wren}}==
338

edits