Determine if a string has all the same characters: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
|||
Line 35: | Line 35: | ||
{{Template:Strings}} |
{{Template:Strings}} |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|Kotlin}} |
|||
<lang 11l>F analyze(s) |
|||
print(‘Examining [’s‘] which has a length of ’s.len‘:’) |
|||
I s.len > 1 |
|||
V b = s[0] |
|||
L(c) s |
|||
V i = L.index |
|||
I c != b |
|||
print(‘ Not all characters in the string are the same.’) |
|||
print(‘ '’c‘' (0x’hex(c.code)‘) is different at position ’i) |
|||
R |
|||
print(‘ All characters in the string are the same.’) |
|||
V strs = [‘’, ‘ ’, ‘2’, ‘333’, ‘.55’, ‘tttTTT’, ‘4444 444k’] |
|||
L(s) strs |
|||
analyze(s)</lang> |
|||
{{out}} |
|||
<pre> |
|||
Examining [] which has a length of 0: |
|||
All characters in the string are the same. |
|||
Examining [ ] which has a length of 3: |
|||
All characters in the string are the same. |
|||
Examining [2] which has a length of 1: |
|||
All characters in the string are the same. |
|||
Examining [333] which has a length of 3: |
|||
All characters in the string are the same. |
|||
Examining [.55] which has a length of 3: |
|||
Not all characters in the string are the same. |
|||
'5' (0x35) is different at position 1 |
|||
Examining [tttTTT] which has a length of 6: |
|||
Not all characters in the string are the same. |
|||
'T' (0x54) is different at position 3 |
|||
Examining [4444 444k] which has a length of 9: |
|||
Not all characters in the string are the same. |
|||
' ' (0x20) is different at position 4 |
|||
</pre> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |