0

The problem I am trying to solve looks like this, take an address string:

"Street, City, State"

and split it into ["Street", "City", "State"], in order to do this I am trying to use elemIndex like:

elemIndex "," "a, b, c"

but I realize that this violates the type signature of

elemIndex :: String -> List String -> Maybe Int

and tried a variation with characters because [Char] and String are the same type.

elemIndex ',' "a, b, c"

but that results in a type error as well. Which function is appropriate to do this if elemIndex is not appropriate to solve this problem.

vamsiampolu
  • 6,328
  • 19
  • 82
  • 183

1 Answers1

2

I think you are looking for the split function. The type definition is as follows:

split :: Pattern -> String -> Array String

You should use it as follows:

split (Pattern ", ") "Street, City, State"

You can view its documentation here: https://pursuit.purescript.org/packages/purescript-strings/3.3.0/docs/Data.String#v:split

DevNebulae
  • 4,566
  • 3
  • 16
  • 27