RosettaCodeData/Task/Determine-if-a-string-has-all-the-same-characters/FreeBASIC/determine-if-a-string-has-all-the-same-characters.basic
2023-07-01 13:44:08 -04:00

23 lines
558 B
Text

dim as string s, nxt
input "Enter string: ", s
if len(s)<2 then 'A string with one or zero characters passes by default
print "All characters are the same."
end
end if
dim as ubyte i
for i = 1 to len(s)-1
nxt = mid(s, i+1, 1)
if mid(s, i, 1)<>nxt then 'if any character differs from the previous one
print "First non-matching char is "+nxt
print "It occurs at position "+str(i+1)
print "Its hex value is "+hex(asc(nxt))
end
end if
next i
'otherwise, success!
print "All characters are the same."