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

m (→‎{{header|REXX}}: added zkl header)
(→‎{{header|zkl}}: added code)
Line 312:
 
=={{header|zkl}}==
<lang zkl>fcn stringSameness(str){ // Does not handle Unicode
<lang zkl></lang>
sz,unique,uz := str.len(), str.unique(), unique.len();
<lang zkl></lang>
println("Length %d: \"%s\"".fmt(sz,str));
if(sz==uz or uz==1) println("\tConsists of a single charcter");
else
println("\tUnique: ",
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)) })
.concat(", "));
<lang zkl>}</lang>
<lang zkl>testStrings:=T("", " ", "2", "333", ".55", "tttTTT", "4444 444k");
foreach s in (testStrings){ stringSameness(s) }</lang>
{{out}}
<pre>
ength 0: ""
 
Consists of a single charcter
Length 3: " "
Consists of a single charcter
Length 1: "2"
Consists of a single charcter
Length 3: "333"
Consists of a single charcter
Length 3: ".55"
Unique: '.' (0x2e)[0], '5' (0x35)[1]
Length 6: "tttTTT"
Unique: 't' (0x74)[0], 'T' (0x54)[3]
Length 9: "4444 444k"
Unique: '4' (0x34)[0], ' ' (0x20)[4], 'k' (0x6b)[8]
</pre>
Anonymous user