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

Content added Content deleted
(Added S-BASIC example)
(→‎{{header|S-BASIC}}: revamp output display)
Line 3,514: Line 3,514:
end = result
end = result


procedure report(str = string)
rem - examine test cases
var p = integer
print "Test string "; chr(34); str; chr(34); \
" has length ="; len(str)
p = samechars(str)
if p = 0 then
print "The characters are all the same"
else
print "Characters differ starting at position";p;" ('"; \
mid(str,p,1);"'=";right$(hex$(asc(mid(str,p,1))),2);"h)"
print
end


rem - apply to the test cases
var str = string
var p = integer


report ""
while 1 = 1 do
report " "
begin
report "2"
rem - ^C at prompt will end program
report "333"
input "string to test: "; str
report ".55"
print "The test string "; chr(34); str; chr(34); \
report "tttTTT"
" has length ="; len(str)
report "4444 444k"
p = samechars(str)
if p = 0 then
print "The characters are all the same"
else
print "Characters differ at position";p;" ('"; \
mid(str,p,1);"'=";right$(hex$(asc(mid(str,p,1))),2);"h)"
print
end


end
end
Line 3,538: Line 3,541:
{{out}}
{{out}}
<pre>
<pre>
string to test:
Test string "" has length = 0
The test string "" has length = 0
The characters are all the same
The characters are all the same


string to test:
Test string " " has length = 0
The test string " " has length = 0
The characters are all the same
The characters are all the same


string to test: 2
Test string "2" has length = 1
The test string "2" has length = 1
The characters are all the same
The characters are all the same


string to test: 333
Test string "333" has length = 3
The test string "333" has length = 3
The characters are all the same
The characters are all the same


string to test: .55
Test string ".55" has length = 3
Characters differ starting at position 2 ('5'=35h)
The test string ".55" has length = 3
Characters differ at position 2 ('5' = 35h)


string to test: tttTTT
Test string "tttTTT" has length = 6
Characters differ starting at position 4 ('T'=54h)
The test string "tttTTT" has length = 6
Characters differ at position 4 ('T' = 54h)


string to test: 4444 444k
Test string "4444 444k" has length = 9
Characters differ starting at position 5 (' '=20h)
The test string "4444 444k" has length = 10
Characters differ at position 5 (' ' = 20h)
</pre>
</pre>



=={{header|Scala}}==
=={{header|Scala}}==