Many times, the IVR will require us to get a string and either break it into usable subparts or, sometimes, insert other characters, including spaces, into the string.

The tools we will use for this are three Java functions, '.split()', '.join()', and '.substring()'.


'.split()' breaks apart the string at the spot described in the argument. For example, '.split("")' says to break apart the string between every element; '.split("|")' says to break it apart every time it reaches the "pipe" character ( | ); '.split(",")' says to break it apart every time it reaches a comma.


'.join()' puts the string back together with whatever character is indicated by the argument inserted between the previously split elements. For example, '.join("|")' puts the string back together with the "pipe" as a delimiter;

'.join(" ")' puts the string back with a space between the elements. This is used to "explode" a number for correct text-to-speech playback (see below).


'.substring()' grabs a particular part of the string. The argument should say which place in the string to start with, and how many places to grab. Keep in mind that when counting places in strings or arrays, you always start with '0' (zero). So, '.substring(0,3)' would begin with the first element of a string, and grab the first three elements. An example would be the area code from a 10-digit phone number. See below for the real-world examples.

The last piece of coding associated with this is the array place reference. You can grab a particular part of a string array by referencing its place in the array in brackets following the split argument. For example, '.split(",")[1]' says to split the array at the comma delimiter and take the second item in the array (since the count starts with "0", "1" is the second place).

Here are some real-world examples

To "explode" a number for correct TTS playback, we would need to split each element (number) in the string and insert a space between them. Assuming our "number" is the variable 'acctNum', our tag would look like this:

${acctNum}.split("").join(" ");

(The semicolon ';' is used to end a Java command.)

Suppose we sent an account ID using a get tag, and got back a variable ('myResult') that contained three elements — the user name, account balance, and due date — separated by a 'pipe' ( | ) delimiter. We could take the results of the Get Tag ('myResult') and split it into the three elements at the pipe delimiter, and place each element into its own variable:


To grab the area code from the caller ID, do the following: