# KeepChar - script and chart function

KeepChar() returns a string consisting of the first string ,'text', less any of the characters NOT contained in the second string, "keep\_chars".

Syntax:

KeepChar(text, keep\_chars)

Return data type: string

Arguments:

Arguments

| Argument | Description |
| --- | --- |
| text | The original string. |
| keep\_chars | A string containing the characters in text to be kept. |

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/KeepChar.htm)

#### Example: Chart expressions

| Example | Result |
| --- | --- |
| `KeepChar<br>( 'a1b2c3','123' )` | Returns '123'. |
| `KeepChar<br>( 'a1b2c3','1234' )` | Returns '123'. |
| `KeepChar<br>( 'a1b22c3','1234' )` | Returns '1223'. |
| `KeepChar<br>( 'a1b2c3','312' )` | Returns '123'. |

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/KeepChar.htm)

#### Example: Load script and results

```
T1:
Load 
*, 
keepchar(String1, String2) as KeepChar;  
Load * inline [
String1, String2
'a1b2c3', '123'
]; 
				
```

Results

Qlik SenseQlik Sense table showing the output from using the KeepCharKeepChar function in the load script.

| String1 | String2 | KeepChar |
| --- | --- | --- |
| a1b2c3 | 123 | 123 |

## Learn more

* [PurgeChar - script and chart function](https://help.qlik.com/en-US/sense/May2025/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/PurgeChar.htm)