User manual
205
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
Strings
A string represents a sequence of characters equivalent to an array of char. It is declared like this:
string_name : string[length]
The specier length is a number of characters the string consists of. The string is stored internally as the given
sequence of characters plus a nal null character (zero) which is introduced to terminate the string. It does not count
against the string’s total length.
A null string (‘’) is stored as a single null character.
You can assign string literals or other strings to string variables. String on the right side of an assignment operator has
to be shorter or of equal length than the one on the right side. For example:
var
msg1 : string[20];
msg2 : string[19];
begin
msg1 := ‘This is some message’;
msg2 := ‘Yet another message’;
msg1 := msg2; // this is ok, but vice versa would be illegal
Alternately, you can handle strings element–by–element. For example:
var s : string[5];
...
s := ‘mik’;
{
s[0] is char literal ‘m’
s[1] is char literal ‘i’
s[2] is char literal ‘k’
s[3] is zero
s[4] is undened
s[5] is undened
}
Be careful when handling strings in this way, since overwriting the end of a string will cause an unpredictable
behavior.
String Concatenating
mikroPascal PRO for dsPIC30/33 and PIC24 allows you to concatenate strings by means of plus operator. This kind of
concatenation is applicable to string variables/literals, character variables/literals. For control characters, use the non-
quoted hash sign and a numeral (e.g. #13 for CR).