String Manipulation

Hi there,

I have a problem with the string manipulation. This might be a very simple question for the most of you here, however I am not familiar with java and thus I have no idea how to create the variable that I want. I hope there is someone that can help.

I have a string that always starts with 48 and then has a couple of numbers afterwards. The numbers are not always the same count, sometimes there is 5 numbers after, sometimes 10. It is the longitude of Stuttgart. To work with the data, I need to have a β€œ.” after each 48, so that for example the string says β€œ48.36789” or β€œ48.345”. Is there a way to use the String Manipulation to get the results I need?

Thank you so much to anyone that can help in advance!!

Best
Theresa

Hi Theresa,

you can do this with the β€œString Manipulationen Node”

With something like this:
join(
substr($yourStringCol$, 0, 2)
,"."
,substr(
$yourStringCol$,2
,length($yourStringCol$) - 2)
)

*my first thought about just replacing β€œ48” with β€œ48.” will replace also die 48 in the following numbers:
But with the string replace node and a regex like
Pattern: ^([0-9]{2})
Replacement text $1.
it should work just fine :slight_smile:

Or in your case
Pattern: ^(48)
Replacement text $1.

Attached a small example :stuck_out_tongue:
KNIME_project6.knwf (7.7 KB)

3 Likes

*and in case your column is currently an integer you can use the String to Number Node beforehand :slight_smile:

Thank you so much!!! It worked perfectly!! Already had spent hours on it. Thank you again!

1 Like

Great! :slight_smile:
In case you often have to modify string or extract certain parts of strings/texts- then I would suggest to look into the regex syntax (it is easier then it looks) or check the different string manipulation functions.
Regex will solve most string related tasks (and the different string manipulation functions are often quite helpful)

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