val lines : String = ("a1 , test1 , test2 , a2 , test3 , test4")
I'd like to convert this to a list of Strings where each string in the list contains 3 elements so above list is converted to 2 element list of strings containing "a1 , test1 , test2" and "a2 , test3 , test4"
One option I have considered is to iterate over each cvs element in the string and if on an element which is the current third element then add then add the previous elements to a new string. Is there a more functional approach?
splitoperation will have its problems, because then, how would you put a comma inside a cell value? - Writing a CSV parser is not quite that easy. You're better off using one of the readymade CSV parser libraries.