Strings are collections of characters.
Operations can be used on strings as well as numbers. Example 1 shows the concatenation (joining) of two strings using the +
operator.
Example 1
"abc" + "def" # "abcdef"
Strings can be represented as arrays of characters, and we can index them starting from 0.
Diagram 1 shows how the string "Hello, World!"
is indexed.
Diagram 1
Table 1 shows the string manipulation functions in pseudo-code.
Table 1
Function | Description | Example | Result |
---|---|---|---|
LEN |
Length: returns the number of characters in a string. | LEN("Hello, World!") |
13 |
POSITION |
Returns the index of the first occurrence of a character in a string. | POSITION("Hello, World!", 'o') |
4 |
SUBSTRING |
Returns the part of the string from the start index to the end index. | SUBSTRING(3, 7, "Hello, World!") |
"lo, W" |
ASCII is a code which assigns each character a unique number. It will be explained further in 3.05 (ASCII and Unicode).
Table 2 shows the ASCII functions in pseudo-code.
Table 2
Function | Description | Example | Result |
---|---|---|---|
CHAR_TO_CODE |
Converts a character to its ASCII value. | CHAR_TO_CODE('A') |
65 |
CODE_TO_CHAR |
Converts an ASCII value to its character. | CODE_TO_CHAR(65) |
'A' |
What is the output of
SUBSTRING(POSITION(a, 'l'), LEN(a)-1, a)
when a = "Hello"
?
"llo"