Operators for Characters in Text
CreatiCode last edited by info-creaticode
A “text” is also called a “string”. It is made of one or more characters. Each character can be a letter (such as “a” or “X”), a digit (0 to 9) or a symbol (such as “+” or “!”).
We can use text to represent all kinds of information, such as the name of a person, the title of a book, or the content of a piece of news.
Let’s look at some operator blocks for working with text below.
The “length” of a text refers to the number of characters in it.
For example, the text “hello” contains 5 letters, so its length is 5. The text “Let’s go!” contains 6 letters and 3 symbols (including the space), so its length is 9.
You can get the character at any position in a text using the “letter (position) of (text)” block. Note that this block will not only find the letter by its position, but also find the digit or symbol at a position.
Note that if you use a position that is less than 1 or more than the length of the text, this block will report an empty value (not the same as the “space” symbol).
We can also ask for the position of a character in a text. For example, in the text “abcd”, the letter “b” is at position 2, and “d” is at position 4:
If a text contains the same character multiple times, this block will report the position of the first one:
If the character is not found in the text, a value of 0 will be reported. Note that upper case and lower case letters are treated as the same.