Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

 

String Functions

These are built-in functions available on the String namespace.

concat

Returns a string value that is the concatenated result of two or more arguments passed to the function. Null values are treated as empty strings.

 

string s = String:concat("abc","def");

 

split

Returns an array of string values that represent the tokens from the value expression that are separated by the separator expression.

Note that in order to split a special character such as '|', one needs to escape the string with a '\' character.  The '\' may need to be escaped as well, so in this case one will end up with String:split(someText, "\\|").

 

string[] result = String:split("abc def", " ");
string first = result.get(0); //first = "abc"
string second = result.get(1); //second = "def"

 

length

Returns the length of the string argument.

int i = String:length("Hello world");

 

substring

Substring of a string based on index positions.

string s = String:substring("Hello World", 1, 4); //s = "ello"

 

lower

Convert string to lowercase.

string s = String:lower("Hello World"); //s = "hello world"

 

upper

Convert string to uppercase.

string s = String:upper("Hello World"); //s = "HELLO WORLD"

 

startsWith

Check if the beginning part of a string matches another string.

bool b = String:startsWith("Hello World", "Hello"); //b = true

 

endsWith

Check if the ending part of a string matches another string.

bool b = String:endsWith("Hello World", "World"); //b = true

 

indexOf

Returns the index within this string of the first occurrence of the specified substring.

int i = String:indexOf("Hello World", "llo W"); //i = 2

 

join

Joins a collection of strings into one result string with the specified join character.

string[] strings;
strings.append("abc");
strings.append("def");
string s = String:join(strings, " "); //s = "abc def"

 

translate

Fetches the translation from the lang file using the argument as key.

en.lang
message.default_warning = You've been warned.
string s = String:translate("message.default_warning"); //s = "You've been warned."

 

 

 

 

 

  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.