String Functions
This section describes functions that relates to manipulating string values in the APL.
Warning!
The String functions cannot operate on null arguments.
The following functions for String described here are:
String Concatenation
Strings are concatenated with the arithmetic '+' operator:
string str1 = string str2 + string str3 ...
strEndsWith
Returns true
if str
ends with substr
, otherwise false
.
boolean strEndsWith
( string str ,
string substr )
Parameter | Description |
---|---|
| String to examine |
| String to look for |
Returns |
|
strEqualsIgnoreCase
Compares two strings and returns true
if they are equal, and false
if they are not. This comparison ignores case.
boolean strEqualsIgnoreCase
( string str1 ,
string str2 )
Parameter | Description |
---|---|
| A string to compare |
| Another string to compare |
Returns |
|
strIndexOf
Returns the first position where substr
can be found in str
. If substr
is not found, -1
is returned. The position starts to count from 0 (zero), which is the first character.
Parameter | Description |
---|---|
| String to examine |
| String to look for |
| Index where to start the string search. If |
Returns | The position of the first character of |
strLastIndexOf
Returns the last position where substr
 can be found in str
 . If substr
 is not found, -1
 is returned. The position starts to count from 0 (zero), which is the first character.
Parameter | Description |
---|---|
| String to examine |
| String to look for |
| Index where to start the string search. If |
Returns | The position of the last character of |
strInsert
Inserts a string into another at a specific position, and returns the result string.
Parameter | Description |
---|---|
| The string that |
| The string to insert |
| Position where |
Returns | The result string. Note, the |
strLength
Returns the number of characters in a string.
Parameter | Description |
---|---|
| String to examine |
Returns | The number of characters in the string |
strREContains
Returns true
if a string contains a substring, else false
. The function is case sensitive.
Parameter | Description |
---|---|
| String to examine |
| The substring to look for. Regular expressions are allowed. |
Returns |
|
Note!
Regular expressions according to Java syntax applies. For further information, see https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/regex/Pattern.html
Warning!
Using nonconstant regular expressions may consume large amounts of memory and should therefore be avoided.Â
strREIndexOf
Returns the first position where a regular expression can be found in a string. If the regular expression is not found, -1
is returned. The position starts to count from 0 (zero), which is the first character.
Parameter | Description |
---|---|
| String to examine |
| Regular expression to be used when examining |
Returns | The position of the first character of |
strREMatches
Returns true
if the first stated string matches the content of the second string completely. The function is case sensitive.
Parameter | Description |
---|---|
| The first string |
| The second string. Regular expressions are allowed |
Returns |
|
strREReplaceAll
Replaces existing substrings within a string with new values.
Parameter | Description |
---|---|
| String to change |
| The substring to replace. Regular expressions are allowed. |
| The new substring to replace the old. If an empty string is entered, the old will be removed without inserting any new value. |
Returns | The result string |
strReplaceChars
Replaces characters in a string at a given position with another string and returns the new string. If str2
is longer than str1
, then the resulting string will be expanded to fit the complete str2
.
Parameter | Description |
---|---|
| The base string |
| Position where |
| String to use for replacement |
Returns | The result string. Note, the |
strSplit
Splits a string where a given regular expression is matched into a list of strings. The function will try to match the regular expression and split the string as many times as possible.
Parameter | Description |
---|---|
| The base string |
| The regular expression which is to be used to split elements |
Returns | A list of strings |
This function would typically be used for splitting strings of values that are comma separated, colon separated, or similar. The list returned will present the substrings in the order they occur in the original string.
strStartsWith
Returns true
if str
starts with substr
, otherwise false
.
Parameter | Description |
---|---|
| String to examine |
| String to look for |
Returns |
|
strSubstring
Returns a substring from a given string. The extracted substring is from position start
to end
.
Parameter | Description |
---|---|
| The base string |
| Position where to start the substring extraction. Position 0 (zero) points to the first character of |
| Position where to end the extraction. That is, the index of the letter after the last letter in the substring. |
Returns | The substring |
strToLower
Turns all letters in a string to lower-case.
Parameter | Description |
---|---|
| The base string |
Returns | The result string. Note, the |
strToUpper
Turns all letters in a string to capital letters.
Parameter | Description |
---|---|
| The base string |
Returns | The result string. Note, the |
strTrim
Removes leading and trailing spaces from a string and returns the result.
Parameter | Description |
---|---|
| The base string |
Returns | The result string. Note, the |