I need to return two lists, the list of Strings up to and including the first line containing a ’-’ and then the remaining elements.
so i've been trying lst.splitAt('-') but it keeps doing
scala> val lst = List(" Hi this is - a test")
lst: List[String] = List(" Hi this is - a test")
scala> lst.splitAt('-')
res8: (List[String], List[String]) = (List(" Hi this is - a test"),List())
how can i fix this so that i will get (List(" Hi this is -),List( a test")) ?
The argument to
List
's splitAt is anInt
. your '-' is being coerced to 45 and trying to split the list at index 45.You can do this for a single string:
The result of this (in sbt) is:
You can map this function over a list of strings if you want:
The result of this is: