Split by first space

Hi dear KNIMErs

Is there a way only to split by the first “space” character (the most left one so to say)?

I have a table (see screenshot, attached workflow), in which the first “item” is always the company number and everything that follows is the company name.

As a result, I wish for one column that holds the company number and one that holds the company name.

The length of these “data points” however can change, e. g. company number can be 2 or 3 or 4 digits, company name can be one or multiple “words”.

Thank you in advance!

Phil

split-by-space-problem.knwf (6.6 KB)

PS. I came close with these posts here and here but didn’t make it as dynamic to care for especially the “differing” lengths of items.

You can use the regex splitter :


split-by-space-problem.knwf (6.4 KB)

7 Likes

Hi Phil,

why not use the String Manipulation node:
substr($Company Code$, 0,indexOf($Company Code$," " ) )
-> this takes the substring from “company code” beginning at index zero till the first occurence of the space character
and for the second column, just change it to
substr($Company Code$, indexOf($Company Code$," " )+1 )

Best,
Alec

2 Likes

Considering cases where the first part of the string is not only digits, I suggest this regex in the solution by @lisovyi although it is already alright and works fine in your examples.
(.*?) (.*)
I’m sharing this in case any other user has the same issue but the first part of the string is not only digits.

Best,
Armin

3 Likes

Hi @kowisoft,

in your workspace set the ‘set array size’ = 2 in the Cell-Splitter and that’s all.

Andrew

6 Likes

Thank you everyone, every single solution works. Wow that’s amazing!

Now I am left with one problem, which one do I mark as the solution to this question (to close the thread) :wink:

Phil

ps: I chose first response…
pps: for anyone who needs an exmaple workflow, here it is incl all 4 solutions:
split-by-space-problem-solved.knwf (13.1 KB)

6 Likes

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