QBASIC - Functions - String
| INSTR | LCASE$ | LEFT$ | LEN | LTRIM$ | MID$ | RIGHT$ | RTRIM$ | SPACE$ | STRING$ | UCASE$ |
 
INSTR()
Returns the position of the first occurrence of a string in another string.
INSTR([start%,]stringexpression1$,stringexpression2$)
start%    Sets the character position where the search begins.
If start% is omitted, INSTR starts at position 1.
stringexpression1$ The string to search.
stringexpression2$ The string to look for.

Ex:

a$ = "Microsoft QBasic"
PRINT "String position ="; INSTR(1, a$, "QBasic")

String position = 11

 

LCASE$()
Convert strings to all lowercase letters.
LCASE$(stringexpression$)
stringexpression$    Any string expression.
Ex:
Test$ = "THE string"
PRINT Test$
PRINT LCASE$(Test$); " in lowercase"
 
THE string
the string in lowercase
>UCASE$()
 
LEFT$()
Return a specified number of leftmost characters in a string.
LEFT$(stringexpression$,n%)
stringexpression$    Any string expression.
n% The number of characters to return, beginning with the leftmost string character.

Ex:

a$ = "Microsoft QBasic"
PRINT LEFT$(a$, 5)

Micro
>RIGHT$()
 
LEN(string)
Returns the number of characters in a string -
or the number of bytes required to store a variable.
LEN(stringexpression$)
LEN(variable)
stringexpression$    Any string expression.
variable Any nonstring variable.
Ex (string):
a$ = "Microsoft QBasic"
PRINT LEN(a$)
 
16

Ex (variable):

DIM a%, a&, a!, a#
PRINT "INTEGER", LEN(a%)
PRINT "LONG", LEN(a&)
PRINT "SINGLE", LEN(a!)
PRINT "DOUBLE", LEN(a#)
  
TYPE rec
  age AS INTEGER
  addr AS STRING * 20
END TYPE
DIM r AS rec
PRINT "record type", LEN(r)
  
INTEGER      2
LONG         4
SINGLE       4
DOUBLE       8
  
  
  
  
  
  
record type  22
 
LTRIM$()
 
MID$()
The MID$ function returns part of a string (a substring).
MID$(stringexpression$,start%[,length%])
stringexpression$    The string from which MID$() returns a substring.
start% The position of the first character in the substring being returned.
length% The number of characters in the substring.
If the length is omitted, MID$() returns all characters to the right of the start position.
Ex:
a$ = "Where is Paris?"
PRINT MID$(a$, 10, 5)
 
Paris

>Statement: MID$

 
RIGHT$(string, n)
Return a specified number of rightmost characters in a string.
LEFT$(stringexpression$,n%)
stringexpression$    Any string expression.
n% The number of characters to return, beginning with the rightmost string character.

Ex:

a$ = "Microsoft QBasic"
PRINT RIGHT$(a$, 5)

Basic
>LEFT$()
 
RTRIM$
 
STRING$
 
SPACE$
 
UCASE$
Convert strings to all uppercase letters.
UCASE$(stringexpression$)
stringexpression$    Any string expression.
Ex:
Test$ = "THE string"
PRINT Test$
PRINT UCASE$(Test$); " IN UPPERCASE"
 
THE string
THE STRING

>LCASE$()