QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

STRING variables or literal values are one byte per character length text or ASCII characters.

Syntax

DIM variable AS STRING [* byte_length]

Creating a fixed length STRING variable

QB64 fixed length string type suffixes

Must be used when defining a string variable’s literal value!

Example(s)

Using a string type suffix with a fixed length byte size in QB64 only. The number designates the fixed string length.


var$5 = "1234567"

PRINT var$5 


12345

Note: The suffix must keep the same byte length or it is considered a different string variable with a different value!

Creating a string variable value by adding variable and literal string values. This procedure is called string concatenation.


age% = 10
a$ = "I am " + CHR$(34) + LTRIM$(STR$(age%)) + CHR$(34) + " years old."
b$ = "How old are you?"
question$ = a$ + SPACE$(1) + b$
PRINT question$


I am "10" years old. How old are you? 

Note: Since quotation marks are used to denote the ends of literal strings, CHR$(34) must be used to place quotes inside them.

How QB64 string type suffixes can fix the length by adding a number of bytes after it.


strings$5 = "Hello world"

PRINT strings$5 


Hello

STRING values can be compared by the ASC code value according to ASCII.


PRINT "Enter a letter, number or punctuation mark from the keyboard: ";
valu$ = INPUT$(1)
PRINT value$
value1$ = "A"
value2$ = "m"
value3$ = "z"

SELECT CASE value$
  CASE value1$: PRINT "A only"
  CASE value1$ TO value2$: PRINT "B to m" 'A is already evaluated
  CASE value1$, value2$, value3$: PRINT "z only" 'A and m are already evaluated
  CASE IS > value2$: PRINT "greater than m but not z" 'z is already evaluated
  CASE ELSE: PRINT "other value" 'key entry below A including all numbers
END SELECT 

Notes: STRING values using multiple characters will be compared by the ASCII code values sequentially from left to right. Once the equivalent code value of one string is larger than the other the evaluation stops. This allows string values to be compared and sorted alphabetically using Greater Than or Less Than and to SWAP values in arrays irregardless of the string lengths.

See Also