-5

From a .txt file I get strings that are full of quotation marks which of course are terrible to use in code. e.g.

 3820,"20170217",8,752,119,"Rh",,"fr",,,,"iC1.2","iC1.2",,"IS6a","Z",,0,"IS6a",,201702161517,"-"

 3821,"20170227",2,753,207,"Dd","Kru","sc",,,,"iB8","iB8",,"IS9b","Z",,2097152,"IS9b",,201702270804,"+~-"

 3822,"20170227",3,753,8,"Dd",,"phH_1",,,,"iB8",,,"IS12~IT12","Z",,2097153,"IS12~IT12",C,201702270804,"-"

 3823,"20170227",4,753,29,"Dd",,"phH_1",,,,"iB8",,,"IS11~IT11","Z",,2097153,"IS11~IT11",C,201702270804,"-"

How could I best get rid of these quotation marks?? Thanks in advance

  • Please give some context. Are you trying to paste the above into a Swift source file? – JeremyP Feb 28 '17 at 10:39
  • I'm trying to create an array using all of these strings to later use in an analysis. But when placing it in an array, the quotation marks mess everything up. – John Donk Feb 28 '17 at 10:41
  • 1
    Related: http://stackoverflow.com/questions/42487486/making-text-into-an-array-swift, http://stackoverflow.com/questions/42484311/swift-split-string-to-array-with-exclusion. – Martin R Feb 28 '17 at 10:44

1 Answers1

0

This is CSV, so you'll need to parse it as CSV. There are several problems with your approach:

  • The quotes mess everything up
  • It's a mixture of strings and numbers - you won't be able to use an array
  • There are consecutive commas, that would be illegal in an array literal.

The best approach is to put the data in a file (in your application bundle if you like) and find a CSV parser to read the data. My quick Google yielded SwiftCSV which looks reasonable, but I've never used it.

JeremyP
  • 84,577
  • 15
  • 123
  • 161