Remove of whitespace doesnt work

Hi,

I have a string like “XXXX 1234” and I want to remove the empty space between it. removeChar, strip and strreplace doesnt work. The column is defined as string, string manipulation before works fine, what is the problem here?

Hi @hevilp ,
Without having a copy of your exact data, it is difficult to know what “space” character you have. What looks like a space could be an alternative Unicode space character rather than an actual space as typed on a keyboard. Alternatively it could even be a tab character, that just appears as a space when viewed in a table.

If we can identify what character it actually is, it will be easier to handle, although if your strings only have alphanumeric characters and spaces you could use regexReplace to remove all non-alphanumeric characters
e.g.

regexReplace($column1$,"[^A-Za-z0-9]","")

to specifically remove any kind of Unicode space character you could try:

regexReplace($column1$,"\\p{Zs}","")

But it would probably be useful to know exactly which character code this is. Take a look at this workflow.

Specifically, the lower flow

If you attach a sample of your “problem row” in place of the Table Creator, the output should tell you what the ascii or Unicode for each character is
e.g.

For example, most regular keyboard characters will appear in the ASCII range 32 to 126 with some currency and other symbols/ accented characters in the extended ASCII range 128-255. A regular space character is ascii code 32.

The additional Unicode symbols will appear outside of the ASCII range (0-255)
e.g.

If you know the Unicode of the “space” character that is causing problems, you can handle it better with String Manipulation, using regexReplace,

as you would then be able to use
regexReplace($column1$,"\\uXXXX","")
to remove it. XXXX represents the 4 character Unicode code

Alternatively… KNIME 5.2 has a new node “String Cleaner”. This has the ability to remove a variety of “special” characters:

2 Likes

Hi @hevilp,

Have you tried the String Cleaner node (which @takbb also suggested)? There you have various options to clean string values. Like removing white spaces, non-printable (invisible) characters, etc.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.