L1VM - course 06


Now I will tell you how to use strings in Brackets. Here is a “set” definition of a string:

(set string s hellostr "Hello world!")

Note: the “s” stands for set the string size automatically to the text length! You could define it this way too:

(set string 13 hellostr "Hello world!")

The string is 12 chars long. But we need one char space more to store the binary zero as the string end mark! You should always use the “s” size setting if the string is not changed in the program.

If you need to add chars at the end of the string then you have to increase the size like this:

(set string 256 hellostr "Hello world!")

So now there is space for 255 chars in the string “hellostr”!

You can copy a string to a new one:

(set string s hellostr "Hello world!)
(set string 256 newstr "")

(newstr hellostr :string_copy !)

This copies the string “hellostr” to the string “newstr”.

To add a string to a existing one we can use: “string_cat”:

(set string 256 hellostr "Hello")
(set string s worldstr " world!")

(hellostr worldstr :string_cat !)

Now “hellostr” contains: “Hello world!”.

In my GitHub repo of L1VM there is a string library demo with more functions.

7: loops