String functions library.
| type and name | description | comments |
lenfunction |
string length | String.len("abcdef") -> 6 |
replacefunction |
replace | String.replace("abcdef","cd","X") -> "abXef" |
splitfunction |
split | return the vector of substrings, cut at separator positions.
subsequent separators give empty words: split("word1---word2-word3","-") -> ["word1","","","word2","word3"] |
split2function |
split2 | return the vector of substrings, cut at separator positions.
subsequent separators are treated as one: split("word1---word2-word3","-") -> ["word1","word2","word3"] |
indexOffunction |
search for substring | String.indexOf("abcdef","cd") -> 2
String.indexOf("abcdef","dc") -> -1
|
substrfunction |
substring | String.substr("abcdef",3,2) -> ="de" |
leftfunction |
left substring | String.left("abcdef",3) -> ="abc" |
rightfunction |
right substring | String.right("abcdef",3) -> ="def" |
formatfunction |
formatted string conversion | Works like the standard C library "sprintf()" but only one %-argument is accepted.
Format string: %[-][+][0][width[.precision]]type
-: left adjust (default is right adjust)
+: place a sign (+ or -) before a number
0: the value should be zero padded
width: minimum field width
precision: minimum number of decimal digits
type: d=decimal integer, x/X=hexadecimal integer, f/g=floating point number, e="scientific" style floating point
Examples:
String.format("|%07.2f|",Math.pi) -> ="|0003.14|"
String.format("|%04x|",255) -> ="|00ff|"
String.format("|%7s|","text") -> ="| text|"
String.format("|%-7d|",12345) -> ="|12345 |"
|