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

→‎{{header|S-BASIC}}: revamp output display
(Added S-BASIC example)
(→‎{{header|S-BASIC}}: revamp output display)
 
Line 3,514:
end = result
 
varprocedure report(str = string)
rem - examine test cases
var p = integer
print "The testTest 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 - examineapply 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
Line 3,538 ⟶ 3,541:
{{out}}
<pre>
Test string to"" has length test:= 0
The test string "" has length = 0
The characters are all the same
 
Test string to" test:" has length = 0
The test string " " has length = 0
The characters are all the same
 
Test string to"2" test:has 2length = 1
The test string "2" has length = 1
The characters are all the same
 
Test string to"333" test:has 333length = 3
The test string "333" has length = 3
The characters are all the same
 
Test string to test: ".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)
 
Test string to"tttTTT" test:has tttTTTlength = 6
Characters differ starting at position 4 ('T' = 54h)
The test string "tttTTT" has length = 6
Characters differ at position 4 ('T' = 54h)
 
Test string to test: "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>
 
 
=={{header|Scala}}==
16

edits