Anonymous user
Determine if a string has all the same characters: Difference between revisions
Determine if a string has all the same characters (view source)
Revision as of 20:43, 30 October 2019
, 4 years ago→{{header|zkl}}: change wording
m (elided the forcing of the TOC (table of contents).) |
m (→{{header|zkl}}: change wording) |
||
Line 310:
=={{header|zkl}}==
<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("\
else
println("\
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>
Same character in all positions
Length 3: " "
Same character in all positions
Length 1: "2"
Same character in all positions
Length 3: "333"
Same character in all positions
Length 3: ".55"
Length 6: "tttTTT"
Length 9: "4444 444k"
</pre>
|