User`s manual

String represents a sequence of characters. String type is similar to array, but can
hold only characters.
dim M_name as string[16]
dim Start_message as string[6]
For each string declaration, compiler will reserve the appropriate amount of mem-
ory locations. For example, string M_name will take 16+1 locations; additional
memory location is reserved to contain the length of the string. If we assign string
literal to variable M_name,
M_name = "mik", then:
M_name[0] will be 3 (contains length of the string)
M_name[1] will be 'm'
M_name[2] will be 'i'
M_name[3] will be 'k'
and all other locations will be undefined.
Assignment operator can be used with string variables:
dim M as string[20]
S as string[8]
main:
M = "port"
' Assign 'port' to M
S = "port1"
' Assign 'port1' to S
end.
mikroBasic includes a built-in function Length for working with strings:
sub function Length(dim text as string) as byte
It returns string length as byte, and is quite useful for handling characters within
string:
M = "mikroElektronika"
for i = 1 to Length(M)
Lcd_Chr(PORTD,1,i,M[i])
next i
mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
34
mikroBASIC
MikroElektronika: Development tools - Books - Compilers
making it simple...
page
Strings
Strings and
assignment
Length