Strings in Velo are immutable sequences of characters with built-in methods for manipulation. |
|
Strings are created with double quotes. Escape sequences like \n are supported. |
str greeting = "Hello, World!";
str empty = "";
str multiline = "Line 1\nLine 2";
|
Use len to get the length and sub(start, end) for substrings. |
str s = "Hello, World!";
int length = s.len; # 13
str sub = s.sub(7, 12); # "World"
|
Concatenate strings with the + operator or the con method. |
str a = "Hello";
str b = "World";
str combined = a + ", " + b; # "Hello, World"
str alt = a.con(", ").con(b); # same result
|
Access individual character codes by index. Convert with .char. |
str s = "Hello";
int charCode = s[0]; # character code for 'H'
str firstChar = s[0].char; # "H"
|
Convert between types using .str and .int properties. |
int num = 42;
str numStr = num.str; # "42"
str text = "123";
int parsed = text.int; # 123
|