Good Afternoon KNIME Team,
I am using a string manipulator to change S3 file locations. I’m looking to replace any instance of “%20” with a " “. When I tried to use the String Manipulator with the function: replaceChars($Column$,”%20"," ") all combinations of “20” were being removed.
I didn’t see documentation that % is a wild card character for the String Manipulation node, also unexpected is that the instances of “20” were not being replaced with a space, but being removed from the string.
I found that using the String Replacer node worked as expected. Is there a reason one node worked and the other didn’t?
Function replaceChars() is for replacing characters within string and not sub-strings! It works by mapping first character in chars part to first character in replace part, second to second and so on…
Example: replaceChars($Column$,"%20"," ") will do following:
char % will map to space character (" ")
2 will map to empty string ("") because there is only one character in your replace part
0 will also map to empty string ("")
The result will be that every occurrence of string “%20” will replace with space (which is what you want but not right logic!), each occurrence of string “20” will replace with two empty string what will give you empty string, each occurrence of string “2” or “0” will replace with one empty string.
Conclusion is that replaceChars() function is not to be used in order to replace sub-string within a string Also it is not using % as a wildcard and escape is not necessary for it.
For your use case you can use @mlauber71 solution - replace() function within String Manipulation node with or without escape char