I'm using componentsSeparatedByString on String to split a long String into a String array using the comma (,) as the string to split on. The problem is, one component is the comma character. For example, the string is "a,b,c,,,1,2,3". After calling componentsSeparatedByString the array is ["a", "b", "c", "", "", "1", "2", "3"] but I need it to be ["a", "b", "c", ",", "1", "2", "3"]. Luckily I can modify the string but I really don't want to change all of the commas to a different character. Is there a way I can 'escape' the comma I need as a component such that componentsSeparatedByString won't split on that middle one?
I tried replacing it with \u{002C}, but it was smarter than that. Still interprets that as a comma so it splits on it.
"a,b,c,,,1,2,3"should parse to["a", "b", "c", "", "", "", "1", "2", "3"]. That just makes sense. Perhaps you should use a proper CSV format and a proper CSV parser library? Which means you would quote any item that contains the delimiter character.a,b,c,",",1,2,3. Like this library perhaps: github.com/naoty/SwiftCSV"a,,,,b"? How can it knows if the result is:["a", ",", "", "b"]or["a", "", ",", "b"]?