Determine if a string has all the same characters: Difference between revisions

no edit summary
No edit summary
Line 3,474:
Not all characters in the string are the same.
' ' (0x20) is different at position 4</pre>
 
=={{header|Wren}}==
{{trans|Go}}
<lang vlang>fn analyze(s string) {
chars := s.bytes()
le := chars.len
println("Analyzing $s which has a length of $le:")
if le > 1 {
for i in 1..le{
if chars[i] != chars[i-1] {
println(" Not all characters in the string are the same.")
println(" '${chars[i].ascii_str()}' (0x${chars[i]:x}) is different at position ${i+1}.\n")
return
}
}
}
println(" All characters in the string are the same.\n")
}
fn main() {
strings := [
"",
" ",
"2",
"333",
".55",
"tttTTT",
"4444 444k"
]
for s in strings {
analyze(s)
}
}</lang>
 
{{out}}
<pre>
Analyzing which has a length of 0:
All characters in the string are the same.
 
Analyzing which has a length of 3:
All characters in the string are the same.
 
Analyzing 2 which has a length of 1:
All characters in the string are the same.
 
Analyzing 333 which has a length of 3:
All characters in the string are the same.
 
Analyzing .55 which has a length of 3:
Not all characters in the string are the same.
'5' (0x35) is different at position 2.
 
Analyzing tttTTT which has a length of 6:
Not all characters in the string are the same.
'T' (0x54) is different at position 4.
 
Analyzing 4444 444k which has a length of 9:
Not all characters in the string are the same.
' ' (0x20) is different at position 5.
</pre>
 
=={{header|Wren}}==
338

edits