Split text based on character, but keep 'splitting character'

What about this:

  • replace your splitting character with another uncommon symbol + your character
  • split your text by using the uncommon symbol

For example:

“The quick@ brown fox jum@ps over the lazy dog”
Replace “@” with “%@”
now you have
“The quick%@ brown fox jum%@ps over the lazy dog”
now split by using “%”

The quick
@ brown fox jum
@ps over the lazy dog


text split keeping splitters.gh (12.1 KB)

(The null checking and stream filter is for when you have a single text string input at start…)

5 Likes

Yes, that is a much simpler solution. :+1:

-Kevin

Hi Kevin,

I got one more challenge to go. :slight_smile:

Would it be possible to modify the script in such a way, that the ‘original Path’ is also present in the end result?

e.g. example below:

2023-02-11 Split text and keep splitting character + tree structure.gh (12.6 KB)

Many thanks :slight_smile:

I prefer using C# over Python for manipulating DataTrees.

Here’s how I would do this (slight modification to the C# component I posted before):

Edit: add grasshopper file :man_facepalming:
2023-02-11+Split_txt_keep_splitters+tree_paths_re.gh (12.6 KB)

-Kevin

1 Like