abecedaire.jpg

No strings attached!

Ha! the wonderful world of strings. PPL is the language of choice for strings. It is very versatile, flexible and support many operators you won't see in many languages.

Strings are also managed by an intelligent garbage collector that will create and free the memory as needed.

Variables containing a string are zero-based indexed and are always terminated by a character 0. They can be accessed as arrays to obtain specific characters:

s$ = "ABCDEFG";
c$ = s$[0]; // c$ = "A"
c$ = s$[0, 2]; // c$ = "AB"
c$ = s$[2, 0]; // c$ = "FG"

If the second array element is 0, it will take x characters from the end of the string, where x is the first array element specified.

Some operators support strings just like numbers.

"Hello " + "World!"
This will add two strings together. The result string will now be "Hello World!"

"10" + "20"
Since both strings contain numbers, PPL will convert them to numbers and add them, the result will be a value of 30. It won't be a string anymore. How do I add them as a string to give a result of "1020" you ask?

"10" % "20"
This will concatenate two strings no matter what type they are. The result will be a string "1020". The same thing would have happen by doing "10" % 20 or 10 % 20, the result will be a string "1020".

"ABC" - "B"
This will remove all B's from the "ABC" string. In this example the resulting string will be "AC".

"ABC" - 2
This will truncate the string by 2 characters from the right. The resulting string will be "A".

"ABC" * 2
The string "ABC" will be multiplied two times, the resulting string will be "ABCABC".

"ABC" / 3
This will divide the string "ABC" in three parts. In our case the strings "A", "B" and "C" will be returned to the stack and will need to be stored into variables, to do this do the following:

A$, B$, C$ = "ABC" / 3;

Variable A$ will contain string "A", variable B$ "B" and C$ "C".

It does not stop here. PPL comes with a full set of string functions.

Conversion

PPL variables can store either a string value or a numeric value (double type). You can switch between the two types by doing the following:

a$ = 10;
a$ = str(a$);
a$ = int(a$);

PPL will take care of using the appropriate type when needed you won't have to worry about variable type conversion but sometimes having a little bit of control helps. The following code is perfectly valid:

a$ = 10;
ShowMessage (a$);
a$ = "2";
ShowMessage (mid ("ABCDEF", a$, 2));