PurgeChar() returns a string consisting of the characters contained in the input string ('text'), excluding any that appear in the second argument ('remove_chars').
Syntax:
PurgeChar(text, remove_chars)
Return data type: string
Arguments
Argument
Description
text
The original string.
remove_chars
A string containing the characters in text to be removed.
Example: Chart expressions
Example
Result
PurgeChar( 'a1b2c3','123' )
Returns abc
PurgeChar( 'a1b2c3','1234' )
Returns abc
PurgeChar( 'a1b22c3','1234' )
Returns abc
PurgeChar( 'a1b2c3','312' )
Returns abc
PurgeChar ( 'a1b2c3','Abc' )
Returns a123
Example - PurgeChar fundamentals
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset which is loaded into a data table called Example.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
InputText
CharsToPurge
Create the following calculated dimension:
=PurgeChar(InputText,CharsToPurge), to calculate the characters in InputText that match the characters in CharsToPurge and return only those characters that do not match.
Results table
InputText
CharsToPurge
PurgeChar(InputText,CharsToPurge)
A^b^c
A^
bc
a^b^c
^
abc
a1b2c3
123
abc
The output of the PurgeChar function returns only those characters from InputText that do not match the characters in CharsToPurge. For example, the first line returns bc and removes the other characters.
The following code shows how to use the function in a load script.
A dataset contains customer names and phone numbers. This example parses the phone number strings to retain only numerical characters and discard all other characters, such as parentheses, dashes, periods, plus signs, and spaces.
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset which is loaded into a data table called Example.
The following fields in the data table:
CustomerName
PhoneNumber
Load script
Example:
Load * inline [
CustomerName, PhoneNumber
John Doe, (123) 456-7890
Jane Smith, 123-456-7890
Bob Johnson, 123.456.7890
Alice Brown, +1 (123) 456 7890
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
CustomerName
PhoneNumber
Create the following calculated dimension:
=PurgeChar(PhoneNumber, '()- .+ '), to extract the non-numeric characters from the PhoneNumber field and return only numeric characters.
Results table
CustomerName
PhoneNumber
PurgeChar(PhoneNumber,'()-.+ ')
Alice Brown
+1 (123) 456 7890
11234567890
Bob Johnson
123.456.7890
1234567890
Jane Smith
123-456-7890
1234567890
John Doe
(123) 456-7890
1234567890
The output of the PurgeChar function has successfully removed all non-numeric characters from the PhoneNumber string and returned only numbers.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. The information does not usually directly identify you, but it makes the site work as you expect it to and can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies by clicking on the different category headings to find out more and change your settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
Privacy & Cookie Notice
Manage Consent Preferences
Strictly Necessary Cookies
Always Active
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work.
Functional Cookies
These cookies enable the website to provide enhanced functionality and personalization. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies, then some or all of these services may not function properly. These cookies do not typically store personal information enabling us to identify you, but are based on uniquely identifying your browser and internet device.
Performance Cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site and make it easier to navigate. For example, they help us to know which pages are the most and least popular and see how visitors move around the site. When analyzing this data it is typically done on an aggregated (anonymous) basis.
Advertising Cookies
These cookies may be set through our site by our advertising partners to build a profile of your interests and show you relevant advertisements on other sites. They do not typically store personal information enabling us to identify you, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less relevant advertising.