String Built-in Functions
These built-in functions are accessed via the pseudo unit “String”
String:concat
Returns a string value that is the concatenated result of two or more arguments passed to the function. As of Helium 1.3.1 null values will be treated as empty strings.
Info |
---|
- @Test
- void testConcatenate(){
- Assert:isEqual("abcdef", String:concat("abc","def"), "Concatenate returned an incorrect string");
- Assert:isEqual("abcdef", String:concat("abc",null,"def"), "Concatenate returned an incorrect string");
- }
|
String: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, "\\|").
Info |
---|
- @Test
- void testSplit(){
- string[] result = String:split("abc def", " ");
-
- Assert:isEqual(2, result.length(), "Split returned an incorrect number of tokens");
- Assert:isEqual(result.get(0), "abc", "Split returned an incorrect first token");
- Assert:isEqual(result.get(1), "def", "Split returned an incorrect second token");
- }
|
String:length
Returns the length of the string being passed
Info |
---|
- int i = String:length("Hello world");
|
String:substring
Substring of a string based on index positions
Info |
---|
- @Test
- void testSubstring(){
- Assert:isEqual("ello", String:substring("Hello World", 1, 4), "String:substring failed");
- Assert:isNotEqual("ello", String:substring("Hello World", 1, 3), "String:substring failed");
- }
|
String:lower
Convert string to lowercase
Info |
---|
- @Test
- void testLower(){
- Assert:isEqual("hello world", String:lower("Hello World"), "String:lower failed");
- Assert:isNotEqual("Hello world", String:lower("Hello World"), "String:lower failed");
- }
|
String:upper
Convert string to uppercase
Info |
---|
- @Test
- void testUpper() {
- Assert:isEqual("HELLO WORLD", String:upper("hello world"), "String:upper failed");
- Assert:isNotEqual("hello world", String:upper("hello world"), "String:upper failed");
- }
|
String:startsWith
Check if a particular string starts with a string
Info |
---|
- @Test
- void testStartsWith(){
- Assert:isTrue(String:startsWith("Hello World", "Hello"), "String:startsWith failed");
- Assert:isFalse(String:startsWith("Hello World", "ello"), "String:startsWith failed");
- }
|
String:endsWith
Check if a particular string ends with a string
Info |
---|
- @Test
- void testEndsWith(){
- Assert:isTrue(String:endsWith("Hello World", "World"), "String:endsWith failed");
- Assert:isFalse(String:endsWith("Hello World", "Worl"), "String:endsWith failed");
- }
|
String:indexOf
Returns the index within this string of the first occurrence of the specified substring.
Info |
---|
- @Test
- void testIndexOf(){
- Assert:isEqual(0, String:indexOf("Hello World", "Hello"), "String:indexOf failed");
- Assert:isEqual(1, String:indexOf("Hello World", "ello "), "String:indexOf failed");
- Assert:isEqual(2, String:indexOf("Hello World", "llo W"), "String:indexOf failed");
- Assert:isEqual(3, String:indexOf("Hello World", "lo Wo"), "String:indexOf failed");
- }
|
String:join
Join a collection of strings into one result string with the specified join character
Info |
---|
- @Test
- void testJoin(){
- string original = "abc def ghi";
- string separator = " ";
- Assert:isEqual(original, String:join(String:split(original, separator), separator), "String:join failed");
- }
|