' OK. Here is a fun little exercise! ' This program converts a string to uppercase / lowercase ' with various methods. See the output screen below ;-) DEFINT A-Z DECLARE FUNCTION SCASE$ (S$) ' Convert to sentence case. DECLARE FUNCTION TCASE$ (S$) ' Convert to title case. DECLARE FUNCTION RCASE$ (S$) ' Reverse case DECLARE FUNCTION XCASE$ (S$) ' Convert to random case DECLARE FUNCTION ECASE$ (S$) ' Convert to every-other-letter to uppercase DECLARE FUNCTION FIRST$ (S$) ' Capitalize the first letter only DECLARE FUNCTION MATCH$ (S$, M$) ' Capitalize matched word only A$ = "Congratulations! You have won a MILLION DOLLARS!!! lol" CLS PRINT PRINT " Original string : "; A$ PRINT PRINT " All lowercase : "; LCASE$(A$) ' Builtin QBASIC function PRINT PRINT " All uppercase : "; UCASE$(A$) ' Builtin QBASIC function PRINT PRINT " Sentence case : "; SCASE$(A$) PRINT PRINT " Title case : "; TCASE$(A$) PRINT PRINT " First letter : "; FIRST$(A$) PRINT PRINT " Reverse case : "; RCASE$(A$) PRINT PRINT " Random case : "; XCASE$(A$) PRINT PRINT " Every other : "; ECASE$(A$) PRINT PRINT " Match word 'ON' : "; MATCH$(A$, "On") END ' This function converts to uppercase every other letter ' of string S$ and returns a new string. FUNCTION ECASE$ (S$) X$ = S$ FOR I = 1 TO LEN(X$) C$ = MID$(X$, I, 1) IF I AND 1 THEN C$ = LCASE$(C$) ELSE C$ = UCASE$(C$) MID$(X$, I, 1) = C$ NEXT I ECASE$ = X$ END FUNCTION ' This function capitalizes the first letter ' of a string and returns a new string. FUNCTION FIRST$ (S$) X$ = LCASE$(S$) FOR I = 1 TO LEN(X$) C = ASC(MID$(X$, I, 1)) IF C > 96 AND C < 123 THEN MID$(X$, I, 1) = UCASE$(MID$(X$, I, 1)) EXIT FOR END IF NEXT I FIRST$ = X$ END FUNCTION ' This function converts to uppercase ' each instance of the word M$ in S$. FUNCTION MATCH$ (S$, M$) X$ = LCASE$(S$) L$ = LCASE$(M$) U$ = UCASE$(M$) FOR I = 1 TO LEN(X$) I = INSTR(I, X$, L$) IF I = 0 THEN EXIT FOR MID$(X$, I, LEN(M$)) = U$ I = I + LEN(M$) - 1 NEXT I MATCH$ = X$ END FUNCTION ' This function reverses uppercase letters with ' lowercase and vice versa. FUNCTION RCASE$ (S$) X$ = S$ FOR I = 1 TO LEN(X$) C$ = MID$(X$, I, 1) a = ASC(C$) IF a > 64 AND a < 91 THEN MID$(X$, I, 1) = LCASE$(C$) ELSEIF a > 96 AND a < 123 THEN MID$(X$, I, 1) = UCASE$(C$) END IF NEXT I RCASE$ = X$ END FUNCTION ' This function capitalizes the first letter of each sentence ' and returns a new string. FUNCTION SCASE$ (S$) X$ = LCASE$(S$) SP$ = " ,:;/\()[]{}<>|-+=" + CHR$(9) + CHR$(10) + CHR$(13) + CHR$(255) NEWSENTENCE = 1 FOR I = 1 TO LEN(X$) C$ = MID$(X$, I, 1) IF INSTR(SP$, C$) THEN ' SKIP WHITE SPACE ELSEIF INSTR(".!?", C$) THEN NEWSENTENCE = 1 ELSEIF NEWSENTENCE THEN MID$(X$, I, 1) = UCASE$(C$) NEWSENTENCE = 0 END IF NEXT I SCASE$ = X$ END FUNCTION ' This function capitalizes the first letter of every word ' and returns a new string. FUNCTION TCASE$ (S$) X$ = LCASE$(S$) FIRSTLETTER = 1 WHITESP$ = " .,:;!?/\()[]{}<>|-+=" + CHR$(9) + CHR$(10) + CHR$(13) + CHR$(255) FOR I = 1 TO LEN(X$) C$ = MID$(X$, I, 1) IF INSTR(WHITESP$, C$) THEN FIRSTLETTER = 1 ELSEIF FIRSTLETTER = 1 THEN MID$(X$, I, 1) = UCASE$(C$) FIRSTLETTER = 0 END IF NEXT I TCASE$ = X$ END FUNCTION ' This function randomly converts some letters to uppercase ' and some letters to lowercase and returns a new string. FUNCTION XCASE$ (S$) X$ = S$ RANDOMIZE TIMER + LEN(X$) FOR I = 1 TO LEN(X$) C$ = MID$(X$, I, 1) IF RND * 30 > 15 THEN C$ = LCASE$(C$) ELSE C$ = UCASE$(C$) MID$(X$, I, 1) = C$ NEXT I XCASE$ = X$ END FUNCTION