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

Parameter

Description

str

String to examine

substr

String to look for

Returns

true or false



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

Parameter

Description

str1

A string to compare

str2

Another string to compare

Returns

true or false



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

Parameter

Description

str

String to examine

substr

String to look for

startIndex

Index where to start the string search. If startIndex is not specified, the string is searched from the beginning.

Returns

The position of the first character of substr within str . If not found, -1 is returned.

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

Parameter

Description

str

String to examine

substr

String to look for

startIndex

Index where to start the string search. If startIndex is not specified, the string is searched from the beginning.

Returns

The position of the last character of substr within str . If not found, -1 is returned.



strInsert

Inserts a string into another at a specific position, and returns the result string.



Parameter

Description

Parameter

Description

str1

The string that str2 is inserted into

str2

The string to insert

position

Position where str2 will be inserted. Position 0 (zero) indicates prior to the first character of str1 .

Returns

The result string. Note, the str1 and str2 are not modified.



strLength

Returns the number of characters in a string.



Parameter

Description

Parameter

Description

str

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

Parameter

Description

str

String to examine

regexp

The substring to look for. Regular expressions are allowed.

Returns

true or false



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

Parameter

Description

str

String to examine

regexp

Regular expression to be used when examining str , using case sensitive and contains (not matches).

Returns

The position of the first character of regexp within str . If not found, -1 is returned.









strREMatches

Returns true if the first stated string matches the content of the second string completely. The function is case sensitive.



Parameter

Description

Parameter

Description

str

The first string

regexp

The second string. Regular expressions are allowed

Returns

true or false









strREReplaceAll

Replaces existing substrings within a string with new values.



Parameter

Description

Parameter

Description

str

String to change

old

The substring to replace. Regular expressions are allowed.

new

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

Parameter

Description

str1

The base string

position

Position where str2 will start replacement in str1 . Position 0 (zero) indicates prior to the first character of str1 .

str2

String to use for replacement

Returns

The result string. Note, the str1 and str2 are not modified.





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

Parameter

Description

str

The base string

regex

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

Parameter

Description

str

String to examine

substr

String to look for

Returns

true or false



strSubstring

Returns a substring from a given string. The extracted substring is from position start to end .





Parameter

Description

Parameter

Description

str

The base string

start

Position where to start the substring extraction. Position 0 (zero) points to the first character of str .

end

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

Parameter

Description

str

The base string

Returns

The result string. Note, the str is not modified.



strToUpper

Turns all letters in a string to capital letters.



Parameter

Description

Parameter

Description

str

The base string

Returns

The result string. Note, the str is not modified.



strTrim

Removes leading and trailing spaces from a string and returns the result.



Parameter

Description

Parameter

Description

str

The base string

Returns

The result string. Note, the str is not modified.