main
string s = "ab".copy
print s // LOG: "ab"
Class string is a variable size sequence of Unicode characters.
There are many methods in string class: You may compare two strings. You may search, add, and remove a character or a string from it. You may replace a character or string with another character or string. There are special operations as well: You may split a string into an array of substrings separated by separator, which may be a new line, for instance. You may convert a string to upper or lower case letters or convert an integer an value to string format and vice versa.
Create a new string from 'this'.
main
string s = "ab".copy
print s // LOG: "ab"
Create a new string of length 'n', all characters having value 'c'.
main
string s = new string from 'b' size 10
print s // LOG: "bbbbbbbbbb"
Create new stringview to a part of string.
Modifies a string with a given range (Insert/remove/replace/clear).
Create a new string by concatenating string 's' and 't'.
main
print "ab" & "cd" // LOG: "abcd"
Create a new string that contains 'n' successive copies of 's'.
main
string s = "ab" * 3
print s // LOG: "ababab"
Split 'this' into an array of substrings separated by 'separator'. The separators found are not included in the substrings. If a substring is empty, it's not included in the array. Use this method for instance, if you want to split a text document into an array of rows (separated by new line).
main
string[] sv = "ab-cd--ef".split by "-"
print sv[0] // LOG: "ab"
print sv[1] // LOG: "cd"
print sv[2] // LOG: "ef"
Compare 'this' or optionally, a range of 'this' to 's'.
main
compareResult v
v = "aa".compare to "aa"
if v == EQUAL
print "Equal" // LOG: Equal
v = "aa".compare to "AA" compare mode CASE SENSITIVE
if v != EQUAL
print "Not equal" // LOG: Not equal
v = "c".compare to "cc"
if v == LESS THAN
print "Less than" // LOG: "Less than"
v = "c".compare to "bb"
if v == GREATER THAN
print "Greater than" // LOG: "Greater than"
Check the equality. This is faster than method compare, is just equality is interesting. Optionally you may give a range for 'this'.
main
bool b
b = "".equals to ""
if b
print "true" // LOG: "true"
b = "aa".equals to "aa"
if b
print "true" // LOG: "true"
b = "aa".equals to "AA"
if not b
print "false" // LOG: "false"
b = "aa".equals to "AA" compare mode CASE INSENSITIVE
if b
print "true" // LOG: "true"
Check the equality.
main
if "aa" == "aa"
print "==" // LOG: "=="
Check the inequality.
main
if "aa" != "bb"
print "!=" // LOG: "!="
Comparision.
main
if "aa" < "aaa"
print "<" // LOG: "<"
Comparision.
main
if "aa" <= "aaa"
print "<=" // LOG: "<="
if "aa" <= "aa"
print "<=" // LOG: "<="
Comparision.
main
if "bb" > "b"
print ">" // LOG: ">"
if "c" > "b"
print ">" // LOG: ">"
Comparision.
main
if "bb" >= "b"
print ">" // LOG: ">="
if "c" >= "c"
print ">" // LOG: ">="
Query size of 'this'.
main
print "".get size // LOG: 0
print "ab".get size // LOG: 2
Query the character value at the specified position 'v'.
main
string s = "abc"
print s[1] // LOG: b
Search the first occurrence of a string or character. Optionally you may limit the search in a range.
main
int result
string s = "abcabcabc"
result = s.find first ""
// result == -1
result = s.find first "x"
// result == -1
result = s.find first "bc"
// result == 1
result = s.find first "BC"
// result == 1
result = s.find first "BC" compare mode CASE SENSITIVE
// result == -1
result = s.find first s
// result == 0
Search the last occurrence of a string or character. Optionally you can set compare mode.
main
int result
string s = "abcabcabc"
result = s.find last ""
// result = -1
result = s.find last "x"
// result = -1
result = s.find last "bc"
// result = 7
result = s.find last "BC"
// result = 7
resultRange = s.find last "BC" compare mode CASE SENSITIVE
// result = -1
result = s.find last s
// result = 0
Append. Insert the character 'c' or string 's ' at end.
main
string s = "ab"
s &= "cd"
print s // LOG: "abcd"
s &= ""
print s // LOG: "abcd"
Append itself 'n' - 1 times.
main
string s = "ab"
s *= 3
print s // LOG: "ababab"
Replace every 'occurrence' in 'this' with a string 's' or character 'c'. Optionally you may set compare mode.
main
string s = "azzbzzc"
s.replace every "zz" with "-"
print s // LOG: "a-b-c"
s = "azzbzzc"
s.replace every "ZZ" with "-" compare mode CASE SENSITIVE
print s // LOG: "azzbzzc"
Remove character at position 'v' from 'this'.
main
string s = "abcd"
s.remove 2
print s // LOG: "abd"
s.remove 2
print s // LOG: "ab"
Convert characters of 'this' to lower case using Unicode rules.
main
string s = "ABC"
s.to lower case
print s // LOG: "abc"
Convert characters of 'this' to upper case using Unicode rules.
main
string s = "abc"
s.to upper case
print s // LOG: "ABC"
The method converts the number in 'this' to integer. The number is supposed to be in base 'n' format. The method accepts leading white-spaces. With base 10 (decimal base) it accepts also the minus sign as a mark of a negative number. The method stops reading the string at the first character that it cannot recognize as part of a number.
main
string s
int v
s = " -1234"
v = s.as int
print v // LOG: -1234
s = " 1234"
v = s.as int base 10
print v // LOG: 1234
s = "101110011"
v = s.as int base 2
print v // LOG: 371
s = "FFFA"
v = s.as int base 16
print v // LOG: 65530