# StringHandling routine

The StringHandling routine contains several functions which allow you to carry out various kinds of operations and tests on alphanumeric expressions, based on Java methods.

You can access these functions by double-clicking the StringHandling node under the system routines folder in the Repository tree view.

Functions of the StringHandling routineFunctions of the StringHandlingStringHandling routine

| Function | Description | Syntax |
| --- | --- | --- |
| ALPHA | Checks whether the expression is arranged in alphabetical order.<br>Returns the true or false boolean<br>accordingly. | StringHandling.ALPHA("string to be checked") |
| IS\_ALPHA | Checks whether the expression contains alphabetical characters only,<br>or otherwise. Returns the true or<br>false boolean accordingly. | StringHandling.IS\_ALPHA("string to be checked") |
| CHANGE | Replaces an element of a string with a defined replacement element<br>and returns the new string. | StringHandling.CHANGE("string to be checked", "string to be<br>replaced","replacement string") |
| COUNT | Returns the number of times a substring occurs within a string. | StringHandling.COUNT("string to be checked", "substring to be<br>counted") |
| DOWNCASE | Converts all uppercase letters in an expression into lowercase and<br>returns the new string. | StringHandling.DOWNCASE("string to be converted") |
| UPCASE | Converts all lowercase letters in an expression into uppercase and<br>returns the new string. | StringHandling.UPCASE("string to be converted") |
| DQUOTE | Encloses an expression in double quotation marks. | StringHandling.DQUOTE("string to be enclosed in double<br>quotation marks") |
| EREPLACE | Substitutes all substrings that match the given regular expression in<br>the given old string with the given replacement and returns a new<br>string. | StringHandling.EREPLACE(oldStr, regex, replacement) |
| INDEX | Returns the position of the first character in a specified substring,<br>within a whole string. If the substring specified does not exist in<br>the whole string, the value -1 is returned. | StringHandling.INDEX("string to be checked", "substring<br>specified") |
| LEFT | Specifies a substring which corresponds to the first n characters in<br>a string. | StringHandling.LEFT("string to be checked", number of<br>characters) |
| RIGHT | Specifies a substring which corresponds to the last n characters in a<br>string. | StringHandling.RIGHT("string to be checked", number of<br>characters) |
| LEN | Calculates the length of a string. | StringHandling.LEN("string to check") |
| SPACE | Generates a string consisting of a specified number of blank<br>spaces. | StringHandling.SPACE(number of blank spaces to be<br>generated) |
| SQUOTE | Encloses an expression in single quotation marks. | StringHandling.SQUOTE("string to be enclosed in single<br>quotation marks") |
| STR | Generates a particular character a the number of times specified. | StringHandling.STR('character to be generated', number of<br>times) |
| TRIM | Deletes the spaces and tabs before the first non-blank character in a<br>string and after the last non-blank character, then returns the new<br>string. | StringHandling.TRIM("string to be checked") |
| BTRIM | Deletes all the spaces and tabs after the last non-blank character in<br>a string and returns the new string. | StringHandling.BTRIM("string to be checked") |
| FTRIM | Deletes all the spaces and tabs preceding the first non-blank<br>character in a string. | StringHandling.FTRIM("string to be checked") |
| SUBSTR | Returns a portion of a string. It counts all characters, including<br>blanks, starting at the beginning of the string. | StringHandling.SUBSTR(string, start, length)<br><br><ul> <li> <p> <span>string</span>: the character string you want to										search.</p> </li> <li> <p> <span>start</span>: the position in the string where										you want to start counting.</p> </li> <li> <p> <span>length</span>: the number of characters you										want to return.</p> </li> </ul> |
| LTRIM | Removes blanks or characters from the beginning of a string. | StringHandling.LTRIM(string[, trim\_set])<br><br><ul> <li> <p> <span>string</span>: the string you want to										change.</p> </li> <li> <p> <span>trim_set</span>: the characters you want to										remove from the beginning of the string.											<span>LTRIM</span> will compare the											<span>trim_set</span> to the string										character-by-character, starting with the left side of the										string, and remove characters until it fails to find a										matching character in the <span>trim_set</span>. If										this parameter is not specified, <span>LTRIM</span> will										remove any blanks from the beginning of the string.</p> </li> </ul> |
| RTRIM | Removes blanks or characters from the end of a string. | StringHandling.RTRIM(string[, trim\_set])<br><br><ul> <li> <p> <span>string</span>: the string you want to										change.</p> </li> <li> <p> <span>trim_set</span>: the characters you want to										remove from the ending of the string. <span>RTRIM</span>										will compare the <span>trim_set</span> to the string										character-by-character, starting with the right side of the										string, and remove characters until it fails to find a										matching character in the <span>trim_set</span>. If										this parameter is not specified, <span>RTRIM</span> will										remove any blanks from the ending of the string.</p> </li> </ul> |
| LPAD | Converts a string to a specified length by adding blanks or<br>characters to the beginning of the string. | StringHandling.LPAD(first\_string, length[,<br>second\_string])<br><br><ul> <li> <p> <span>first_string</span>: the string you want to										change.</p> </li> <li> <p> <span>length</span>: the length you want the string										to be after being padded.</p> </li> <li> <p> <span>second_string</span>: the characters you want										to append to the left side of the											<span>first_string</span>.</p> </li> </ul> |
| RPAD | Converts a string to a specified length by adding blanks or<br>characters to the end of the string. | StringHandling.RPAD(first\_string, length[,<br>second\_string])<br><br><ul> <li> <p> <span>first_string</span>: the string you want to										change.</p> </li> <li> <p> <span>length</span>: the length you want the string										to be after being padded.</p> </li> <li> <p> <span>second_string</span>: the characters you want										to append to the right side of the											<span>first_string</span>.</p> </li> </ul> |
| INSTR | Returns the position of a character set in a string, counting from<br>left to right and starting from 1.<br><br>Note that it returns 0 if the search is unsuccessful<br>and NULL if the search value is NULL. | StringHandling.INSTR(string, search\_value, start,<br>occurrence)<br><br><ul> <li> <p> <span>string</span>: the string you want to										search.</p> </li> <li> <p> <span>search_value</span>: the set of characters you										want to search for.</p> </li> <li> <p> <span>start</span>: the position in the string where										you want to start the search. The default is											<span>1</span>, meaning it starts the search from										the first character in the string.</p> </li> <li> <p> <span>occurrence</span>: the occurrence you want to										search for.</p> </li> </ul><br><br>For example, StringHandling.INSTR("Talend Technology", "e",<br>3, 2), it will start the search from the third<br>character l and return 7, the<br>position of the second character e. |
| INSTR | Returns the position of a byte set in a string,<br>counting from left to right and starting from 1.<br><br>Note that it returns 0 if the search<br>is unsuccessful and NULL if the<br>search value is NULL. | StringHandling.INSTR(byte[] string, byte[]<br>search\_value, start, occurrence)<br><br><ul> <li> <p> <span>string</span>: the string you want                                                  to search.</p> </li> <li> <p> <span>search_value</span>: the set of                                                  characters you want to search for.</p> </li> <li> <p> <span>start</span>: the position in the                                                  string where you want to start the search. The                                                  default is <span>1</span>, meaning it starts                                                  the search from the first character in the                                                  string.</p> </li> <li> <p> <span>occurrence</span>: the occurrence                                                  you want to search for.</p> </li> </ul> |
| TO\_CHAR | Converts numeric values to text strings. | StringHandling.TO\_CHAR(numeric\_value) |

## Storing a string in alphabetical order

It is easy to use the ALPHA routine along with a tJava component, to check whether a string is in alphabetical order:

```
System.out.println(StringHandling.ALPHA("abcdefg"));
```

The check returns a boolean value.

![The result is "true" in the Run view.](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/routines6-1.png)

## Checking whether a string is alphabetical

It is easy to use the IS\_ALPHA routine along with a tJava component, to check whether the string is alphabetical:

```
System.out.println(StringHandling.IS_ALPHA("ab33cd"));
```

The check returns a boolean value.

![The result is "false" in the Run view.](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/Routines6_b.png)

## Replacing an element in a string

It is easy to use the CHANGE routine along with a tJava component, to replace one element in a string with another:

```
System.out.println(StringHandling.CHANGE("hello world!", "world", "guy"));
```

The routine replaces the old element with the new element specified.

![The result is "hello guy!" in the Run view.](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/routines6-2.png)

## Checking the position of a specific character or substring, within a string

The INDEX routine is easy to use along with a tJava component, to check whether a string contains a specified character or substring:

```
System.out.println(StringHandling.INDEX("hello world!", "hello"));
                              System.out.println(StringHandling.INDEX("hello world!", "world")); 
                              System.out.println(StringHandling.INDEX("hello world!", "!")); 
                              System.out.println(StringHandling.INDEX("hello world", "?"));
```

The routine returns a whole number which indicates the position of the first character specified, or indeed the first character of the substring specified. Otherwise, -1 is returned if no occurrences are found.

![The result is 0, 6, 11, and -1 in the Run view.](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/Routines6_c.png)

## Calculating the length of a string

The LEN routine is easy to use, along with a tJava component, to check the length of a string:

```
System.out.println(StringHandling.LEN("hello world!"));
```

The check returns a whole number which indicates the length of the chain, including spaces and blank characters.

![The result is 12 in the Run view.](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/routines6-3.png)

## Deleting blank characters

The FTRIM routine is easy to use, along with a tJava component, to delete blank characters from the start of a string:

```
System.out.println(StringHandling.FTRIM("  Hello world  !"));
```

The routine returns the string with the blank characters removed from the beginning.

![The result is "Hello world !" in the Run view.](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/Routines6_d.png)