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

m
→‎{{header|zkl}}: change wording
m (elided the forcing of the TOC (table of contents).)
m (→‎{{header|zkl}}: change wording)
Line 310:
 
=={{header|zkl}}==
 
{{improve|zkl|<br><br> Output is incorrect about ''consists of a single charcter'' (sic)
<br><br> Output is lacking whether or not the characters are the same (or not)
<br><br> Output is missing what the different character is and where it is in the string
<br><br> Output of the word "unique" is misleading and/or incorrect. <br><br> }}
 
<lang zkl>fcn stringSameness(str){ // Does not handle Unicode
sz,unique,uz := str.len(), str.unique(), unique.len();
println("Length %d: \"%s\"".fmt(sz,str));
if(sz==uz or uz==1) println("\tConsiststSame ofcharacter ain singleall charcterpositions");
else
println("\tUniquetDifferent: ",
unique.pump(List, // unique[1,*] if don't want first unique character
'wrap(c){ "'%s' (0x%x)[%d]".fmt(c,c.toAsc(),str.find(c)) })
Line 330 ⟶ 324:
{{out}}
<pre>
engthLength 0: ""
Same character in all positions
Consists of a single charcter
Length 3: " "
Same character in all positions
Consists of a single charcter
Length 1: "2"
Same character in all positions
Consists of a single charcter
Length 3: "333"
Same character in all positions
Consists of a single charcter
Length 3: ".55"
UniqueDifferent: '.' (0x2e)[0], '5' (0x35)[1]
Length 6: "tttTTT"
UniqueDifferent: 't' (0x74)[0], 'T' (0x54)[3]
Length 9: "4444 444k"
UniqueDifferent: '4' (0x34)[0], ' ' (0x20)[4], 'k' (0x6b)[8]
</pre>
Anonymous user