Unexpected results from String Manipulation node

I can’t make sense of some of what I get from String Manipulation in KNIME 3.6.0 in Windows. I am trying to adjust some column values and what comes out doesn’t make sense to me.
For example, if I start with a table like this:
(rowID) fieldname value
Row 1 ms_run[1]-location file://path-to-file1
Row 2 ms_run[2]-location file://path-to-file2

And my goal is to change it to instead say:
(rowID) fieldname value
Row 1 file[1] file://path-to-file1
Row 2 file[2] file://path-to-file2

(note that the number is in the middle of “fieldname” in the original table, I want it at the end)

My first String Manipulation was

Which I expected to remove “-location” from the fieldname. I expected that the return would then be “ms_run[1]” and “ms_run[2]” for those, with nothing else changed. Instead, I get “ms_ru[1]” and “ms_ru[2]”; the letter “n” was dropped from the middle of the string even though I never asked it to do that.

That’s not a big deal, though, as I wanted to change “ms_run” (or “ms_ru” as it is now) into “file”. So my next String Manipulation was

Unfortunately the return of this is now “fi_e[1]” and “fi_e[2]” for the two cells; where I was expecting an “l” (lower-cased “L”) I instead have an underscore.

I can’t explain either of these. Can someone shed light on this?

1 Like

Hi @lparsons42 -

The removeChars() and replaceChars() functions, as best I can tell, are removing a group of individual characters from the string. Thus, when you provide “-location” as an argument, it removes all instances of the character n, including the one found within ms_run. (It’s also removing all instances of l, o, c, etc, but since they only occur once in the string it’s not as obvious what’s happening.)

If you use the replace() function instead, it looks at the string as a whole instead of individual characters, and should provide the output you expect.



When I follow your example in first String Manipulation I get the same as you and it is explained by @ScottF. In second String Manipulation I get “file[1]” which is what you are supposed to get if you change “ms-ru” to “ms_ru”. If he doesn’t find the whole string you specified (and he won’t because there is no “ms-ru”) he maps “ms” to “fi” and “-r” to “l” and “u” to “e” so you get “fi_e” :wink:

In your case I wouldn’t use Chars functions. You can use function join with string “file” and string “[number]” where you extract number from you cell. Something like his:

join("file",substr($column1$, indexOf($column1$,"["),indexOf($column1$,"]")-indexOf($column1$,"[") + 1 ))