Trim Unicode Values
Definition: | trimUnicode(onString: str ) → str |
Description: | Removes instances of Unicode characters from the input string |
Parameters: | onString: The string value from which Unicode characters need to be removed |
Returns: | A new string after removing all instances of Unicode characters from onString |
The following script takes an input string <withUnicode> that contains Unicode characters and removes these characters from it. It then assigns the resulting string to the <withoutUnicode> field in the properties
dictionary.
Note: Replace the placeholder values in the script with your own values.
from io.hevo.api import Event
from io.hevo.api import Utils
def transform(event):
eventName = event.getEventName()
properties = event.getProperties()
<withUnicode> = properties['<field with Unicode characters>']
properties['<withoutUnicode>'] = Utils.trimUnicode(<withUnicode>)
...
Sample Transformation
Consider a variable, name
with value Westeros King P
, where P is the Cyrillic letter represented by Unicode character U0420.
The trimUnicode
function removes the Unicode character \u0420
, and assigns the resulting value to the withoutUnicode
field.
from io.hevo.api import Event
from io.hevo.api import Utils
def transform(event):
eventName = event.getEventName()
properties = event.getProperties()
namewithUnicode = properties['name']
properties['namewithoutUnicode'] = Utils.trimUnicode(namewithUnicode)
return event
Sample Output
The value Westeros King P
is changed to Westeros King
, and the modified value is assigned to the new field, withoutUnicode
.
Last updated on Jun 30, 2023