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

43 lines
930 B
Text

DECLARE SUB DifChar (sString AS STRING, wc AS INTEGER, dc AS STRING)
DIM i AS INTEGER
DIM s AS STRING
DIM dc AS STRING
DATA "", " ", "2", "333",".55","tttTTT", "4444 444k", "FIN"
' Main program cycle
CLS
PRINT "Program SameChar"
PRINT "Determines if a string has the same character or not."
PRINT
DO
READ s
IF s = "FIN" THEN EXIT DO
DifChar s, i, dc
PRINT "'"; s; "' of length"; LEN(s);
IF i < 2 THEN
PRINT "contains all the same character."
ELSE
PRINT "is different at possition"; STR$(i); ": '"; dc; "' (0x"; HEX$(ASC(dc)); ")"
END IF
LOOP
PRINT
PRINT "End of program run."
END
SUB DifChar (sString AS STRING, wc AS INTEGER, dc AS STRING)
' Var
DIM c AS STRING
' Look for the distinct char
c = LEFT$(sString, 1)
wc = 1
dc = ""
DO WHILE wc < LEN(sString)
IF MID$(sString, wc, 1) <> c THEN dc = MID$(sString, wc, 1): EXIT DO
wc = wc + 1
LOOP
IF dc = "" THEN wc = 1
END SUB