4

I want to split a String in Pharo 4. My input is

'a %% b %% c %%% d %% e %% f' 

and I want to get

#('a %% b %% c' 'd %% e %% f')

thus the separator is ' %%% '

In Dolphin 7 it works nice:

'a %% b %% c %%% d %% e %% f' subStrings: ' %%% '
#('a %% b %% c' 'd %% e %% f')

But in Pharo 4 seems to be broken:

'a %% b %% c %%% d %% e %% f' subStrings: ' %%% '
"#('a' 'b' 'c' 'd' 'e' 'f')"

There is a way to get the Dolphin behavior in Pharo?

user1000565
  • 927
  • 4
  • 12
  • Have you considered a simpler approach such as `'a %% b %% c %%% d %% e %% f' readStream upToAll: ' %%% '`? – Leandro Caniglia Apr 05 '16 at 01:33
  • Yes but that would not work with a longer sequence `'a %% b %% c %%% d %% e %% f %%% g %% h %% i' readStream upToAll: ' %%% '` – user1000565 Apr 05 '16 at 03:48
  • Sure, my code was just a hint. You would need to collect the results of `upToAll:` in a `[stream atEnd] whileFalse: [result add: (stream upToAll: ' %%%% ')]` way. – Leandro Caniglia Apr 05 '16 at 20:52

1 Answers1

3

Try

'a %% b %% c %%% d %% e %% f' splitOn: ' %%% '

It also works with

'a %% b %% c %%% d %% e %% f %%% g %% h %% i' splitOn: ' %%% '
John Pfersich
  • 135
  • 2
  • 7