Parsing a string into a List

Hi all,

I am learning Elm, sorry if my question sounds silly.

I have a multiline string in input, something like this:

| foo foo

Something here
Some | more | text

| bar bar

Something else here
bla bla
...

I would like to write a function that takes that string in input and returns a list of string:

[
"""
| foo foo

Something here
Some | more | text
""",
"""
| bar bar

Something else here
bla bla
"""
]

Should I use a Parser for this task?

Thank you

String.split "\n|" inputString
But you would be missing the starting pipe of all blocks Exept the first.

You could also do String.lines and loop over the lines. Accumulate the lines until the next Line start with | character. Then you start a new accumulator :slight_smile:

1 Like

When you say you want to parse it into a List String, how would I know to split at | bar bar. I.e. if you wanted to split on \n then Iā€™d say to do List.split "\n" yourInput, but your input text seems a bit more complex.

Splitting at \n| seems fine!

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