有没有办法确保第一个字符是大写FirstName
的?LastName
DIM FirstName AS STRING
DIM LastName AS STRING
CLS
INPUT "Enter First Name: ", FirstName
INPUT "Enter Last Name: ", LastName
有没有办法确保第一个字符是大写FirstName
的?LastName
DIM FirstName AS STRING
DIM LastName AS STRING
CLS
INPUT "Enter First Name: ", FirstName
INPUT "Enter Last Name: ", LastName
看看这个:
A$ = LEFT$(FirstName$, 1) // get first character
B = ASC(A$) //change it to ascii
IF B >= 65 AND B <= 90 THEN //is it uppercase?
CK$ = "FIRST CHARACTER IS UPPERCASE"
END IF
PRINT CK$
您可以使用字符串函数LEFT$
和UCASE$
串联:
first$ = LEFT$(FirstName, 1)
last$ = LEFT$(LastName, 1)
IF first$ <> UCASE$(first$) OR last$ <> UCASE$(last$) THEN
PRINT "error: first letter of names must be capitalized"
END
END IF
如果您不希望程序退出,您可以使用以下MID$
语句自行将其更改为大写:
first$ = LEFT$(FirstName, 1)
last$ = LEFT$(LastName, 1)
MID$(FirstName, 1, 1) = UCASE$(first$)
MID$(LastName, 1, 1) = UCASE$(last$)
有关字符串操作和转换的更多信息以及其他信息,请参阅 QB64 wiki。