You are here: Using BML > Functions & Scripts > String Functions

String Functions


String data types allow any type of text character to be returned. However, be aware that not all string functions have return values of the string type.

Closedatof() & atoi()

The atof() and atoi() functions convert text that represents a number into either a float or an integer. Example Use Case: Change a string table value into a float/integer value.

Syntax: atof(str) and atoi(str)


Return Type: Integer

Example of atof()/atoi() error messages:

Example of atof() and atoi():


Takes an encoded Base64 string and returns it as a plain text string.

Syntax: decodebase64("str")


# Parameter Data Type Description
1 str String A Base64-encoded string

Return Type: String

Example of decodebase64():

decodebase64("YWJj"); will return the plain text format of the Base64-encoded string parameter. In this example, it is abc.


This function parses the string parameter and converts it into its Base64 equivalent, as an encoded string.

Syntax: encodebase64(str)


Return Type: String

Example of encodebase64():

encodebase64("abc"); will return the Base64 format of String "abc". In this example, it is YWJj.

Example of using encodebase64() for information in a URL string

webSvcsUser = "WebSvcsUserHere";

webSvcsPassword = "WebSvcsPasswordHere";


webSvcResult = dict("string");

headers = dict("string");


httpAuthUserAndPassword = webSvcsUser + ":" + webSvcsPassword;

httpAuthEncodedString = encodebase64(httpAuthUserAndPassword);


put(headers, "Authorization", "Basic " + httpAuthEncodedString);


print _user_session_id;


url = "";

params = "";


webSvcResult = urldata(url, "GET", headers, params);


print webSvcResult;


return "";


The find() function returns the position of a substring within a string.

Example Use Cases:

Syntax: find(str, substring, [start], [end])


Return Type: Integer

Example of find():

This example uses four different variations of the find() function:


Takes a number and returns it as a formatted currency string.

Syntax: formatascurrency(x, [currencyCode])


# Parameter Data Type Description
1 x Float The number to be formatted as a certain currency.
2 currencyCode String Optional: The desired currency.

Return Type: Boolean

Example of formatascurrency():

formatascurrency(32.15, "EUR"); will return the string "€32,15".


This function takes a formatted currency string and returns the string's numeric value. It parses the first parameter using the currency format specified by the currency code passed in the second parameter and returns the float value.

Syntax: getcurrencyvalue(value, [currencyCode])


# Parameter Data Type Description
1 value String The formatted currency string to be converted to a numeric value.
2 [currencyCode] String

Optional: The currency.code to use for parsing the first parameter.

If omitted, this function uses the transaction's currency if used within a commerce transaction. When used elsewhere, the function uses the current user's currency preference.

Return Type: Float or Boolean

Example of getcurrencyvalue():

getcurrencyvalue("€32,15", "EUR"); will return the Float 32.15.


Ths function concatenates a String array into a String with a specified delimiter.

Syntax: join(String[] str_array, String delimiter)


# Parameter Data Type Description
1 str_array Array The original string array.
2 [delimiter] String Optional: Specifies where to put a space between the strings in the array.

Return Type: Boolean

Example of join():

strArr1 = string[]{"1", "2", "3"}; strArr2 = join(strArr1, ""); will set the value of strArr2 to "123".

This function is case-sensitive.


The Boolean function isnumber(str) returns true when the string is a number and false if it contains other characters.

Example Use Case: Check if a table cell contains a number. This check needs to be performed to prevent system errors when converting that value to a number.

Syntax: isnumber(str)


Return Type: Boolean

Example of isnumber():


The len() function returns the length of a string.

Example Use Case: To constrain the length of an input text field.

Syntax: len(str)


Return Type: Integer

Example of len():


Use this function to return a copy of a string, with all occurrences of the old parameter replaced with the new parameter. All occurrences of the old substring are replaced by new. If the optional integer argument is given, only the first n occurrences are replaced.

Example Use Case: You must replace multiple subsets of a string.

Syntax: replace(str, old, new, [n])


Return Type: Copy of String with replacements made.

Example of replace():


This function splits a String at the specified separator, populates a string array, and trims all of the blank spaces from the result.

Syntax: String[] split(str, separator)


# Parameter Data Type Description
1 str String Represents the given input string.
2 separator String  Specifies where to break the string into another section. It represents a variety of separators. However, they must all be enclosed in double-quotes, including spaces.

Return Type: String

Example of split():

strArray = split("a.b.c", ""); will return an array with every character split: ["a",".", "b", ".", "c"] with a size of 5.

    This function is case-sensitive.


This function, as well as endswith(str, substring), checks whether a string starts or ends with a particular substring. For example, if you wanted to see if the value "abc" starts with "a" or if that same string ends with "c", you would use these functions accordingly.

Example Use Case: Determine if a part number starts with a certain text and if a part number contains a specific suffix.

Syntax: startswith(str, substring) & endswith(str, substring)


Return Type: Boolean

Example of startswith():

We know that the return of endResults will be true because the string "I like this string", ends with the substring "string".


Syntax: string(float(integer(boolean)))


Return Type: String

Example of string():


This function is used to pull a subset of a string. This function is case sensitive.

Example Use Cases:

Syntax: substring(str, start, [end])


Return Type: String

Example of substring():

We are performing a number of actions with the substring() function:


This function removes the white space from both edges of strings.

Example Use Case: Compare strings with leading or trailing white space.

Syntax: trim(str)


Return Type: String

Example of trim():

Closedupper() & lower()

These functions convert all characters in the text into all lowercase or uppercase letters.

Example Use Cases:

Syntax: upper(str) & lower(str)


Return Type: String

Example of upper() & lower():

The code will print three different examples:


    NULL and blank Integer values are treated as separate values.

    - NULL= 0
    - Blank = ""

    If you use logic that tests for NULL values in rule conditions or BML, this logic should be updated.

    Using "null" as an attribute value is strongly discouraged.


Related Topics Link IconSee Also