Strings and Runes in Scilab
Our example will demonstrate how strings and characters (called “runes” in some languages) are handled in Scilab. Scilab treats strings as arrays of characters, and it uses UTF-8 encoding for string literals.
In this Scilab code:
We define a string
s
containing Thai characters.We use
length(s)
to get the length of the string, which corresponds to the number of characters.We iterate through the string using a for loop and the
part()
function to access individual characters. We print their ASCII values using theascii()
function.We demonstrate iterating over the string again, this time printing each character and its position.
We define a function
examineChar
that checks if a character matches certain values. This is similar to comparing runes in some other languages.Finally, we use the
examineChar
function on each character of our string.
Note that Scilab doesn’t have a direct equivalent to “runes” or Unicode code points. It treats strings as sequences of characters and doesn’t provide built-in functions for working with Unicode code points directly. The ascii()
function will return the ASCII value for ASCII characters, but may not work as expected for non-ASCII Unicode characters.
To run this Scilab script, save it to a file (e.g., string_example.sce
) and execute it in Scilab:
This will display the results of our string operations and character examinations.