# TalendString routine

The TalendString routine contains several functions which allow you to carry out various operations on alphanumerical expressions.

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

Functions of the TalendString routineFunctions of the TalendStringTalendString routine

| Function | Description | Syntax |
| --- | --- | --- |
| AddEscapeChars | Adds a specified character before each special character (that is, a<br>character that is not a letter, a digit, \_, or space) in a string. | TalendString.addEscapeChars("padding chars",'escape char') |
| replaceSpecialCharForXML | returns a string from which the special characters (eg.:: &lt;, &gt;,<br>&...) have been replaced by equivalent XML characters. | TalendString.replaceSpecialCharForXML("string containing the special<br>characters - eg.: Thelma & Louise") |
| checkCDATAForXML | identifies characters starting with &lt;![CDATA[ and<br>ending with ]]&gt; as pertaining to XML and returns them<br>without modification. Transforms the strings not identified as XML in a<br>form which is compatible with XML and returns them. | TalendString.checkCDATAForXML("string to be parsed") |
| talendTrim | parses the entry string and removes the filler characters from the start and<br>end of the string according to the alignment value specified:<br>-1 for the filler characters at the end of the<br>string, 1 for those at the start of the string and<br>0 for both. Returns the trimmed string. | TalendString.talendTrim("string to be parsed", "filler character to<br>be removed", character position) |
| removeAccents | removes accents from a string and returns the string without the<br>accents. | TalendString.removeAccents("String") |
| getAsciiRandomString | generates a random string with a specific number of characters. | TalendString.getAsciiRandomString(whole number indicating the length<br>of the string) |
| unionString | Combines the variable number of strings with a specified string<br>separator. | TalendString.unionString(String separator,Object...<br>objects) |

## Formatting an XML string

It is easy to run the replaceSpecialCharForXML routine along with a tJava component, to format a string for XML:

```
System.out.println(TalendString.replaceSpecialCharForXML("Thelma & Louise"));
```

In this example, the & character is replaced in order to make the string XML compatible:

![The result is "Thelma &amp; Louise" in the Run view.](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/Routines16_c.png)

## Trimming a string

It is easy to use the talendTrim routine, along with a tJava component to remove the string padding characters from the start and end of the string:

```
System.out.println(TalendString.talendTrim("**talend open Studio****",'*', -1));
               System.out.println(TalendString.talendTrim("**talend open Studio****",'*', 1)); 
               System.out.println(TalendString.talendTrim("**talend open Studio****",'*',0));
```

The star characters are removed from the start, then the end of the string and then finally from both ends:

![The result is "**talend open studio", then "talend open studio****", and "talend open studio" in the Run view.](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/Routines16_b.png)

## Removing accents from a string

It is easy to use the removeAccents routine, along with a tJava component, to replace the accented characters, for example:

```
System.out.println(TalendString.removeAccents("sâcrebleü!"));
```

The accented characters are replaced with non-accented characters:

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