remove no-breack space

Hi,

I have a text column wherein few values show a no-breack space character at the end of the string.

I tried nodes like string manipulation to strip or replace the character and string replacer with no success.

Could anyone suggest me how to remove this disturbing character?

the HEX code is 00A0 or ASCII 160.

Any way to specify the ASCCI code of the character to replace?

Thank you

Fabio

 

Hi Fabio,

A possible option could be to use a Java Snippet (simple) with the following code:

String to_replace = $Col1$;
to_replace = to_replace.replaceAll("\u00A0", "");
return to_replace;

where Col1 is the column containing the strings with the trailing non-breaking space character.

Give it a try and see whether this solves it, otherwise feel free to post again here.

Cheers,
Marco.

 

Thank you Marco. I have a similar problem of not being able to remove ASCII 160. I know this because when I substitute in Excel (TRIM(SUBSTITUTE(CHAR(160),CHAR(32))), it works.

I tried your code in the Java Snippet (Simple) node and it gave me the following error: “Invalid settings; Unable to compile expression ERROR at line 16. Type mismatch: cannot convert from java.land.String to java.lang.Double. Line : 15 to_replace = to_replace.replaceAll(“u00A0”, “”); Line : 16 return to_replace;”

Alternatively, after reading some other posts, I have tried the String Manipulation node: Strip with RegexReplace, RemoveChars, and just Strip.

I have also tried Rule-based Row Filter:
$Col1$ = “” => TRUE; and,
$Col$ = " " => TRUE

Nothing has worked so far.

1 Like

HI there!

The Java Snippet (simple) node is giving error that it can not convert string to double. I guess you left the Return type to be Double what is actually a default. Try changing it to String and run again.

Additionally if I understand what is your problem have you tried strip() function in String Manipulation node?

Br,
Ivan

Thanks for that. I managed to do it using another way:

I used the String Replacer node and asked it to replace Pattern “\u00A0” with blank. Important note: to pick “Regular expression” and for “…all occurrence”

.

That worked!

I did the same for regular space “\u0020.”

To answer your question: the strip function doesn’t remove 00A0 ASCII 160. It only seemed to remove ASCII 32.

1 Like

Is there any chance this could be added as a function to the string manipulator node to remove non breaking space?

I’ve actually made a component that removes all sorts of white space from all string columns - happy to share it if there is a place for that.
I’d love to see this added back to the knime repository

2 Likes

Hi @loneranger -

Please share your component on the KNIME Hub! I’m sure there are several folks here who would like to try it out.

(How do you share via the Hub? Check out this page: https://hub.knime.com/site/about)

2 Likes