实际上我从远程文件中获取此数据
http://appsnurture.com/csv/sample.csv
"\"030506941\"\n\"032752389\"\n\"033415694\"\n\"035010096\"\n\"035010106\"\n\"035010108\"\n\"035010118\"\n
if let url = NSURL(string: "http://appsnurture.com/csv/sample.csv") {
let data = NSData(contentsOfURL: url)
let resstr = NSString(data: data!, encoding: NSUTF8StringEncoding)!
print(resstr)
}
如何在没有引号的情况下解析上面的字符串到数组。 我愿意接受另一个从URL解析CSV的选项。
答案 0 :(得分:1)
请尝试类似
的内容var str = "your string"
var newString = str.stringByReplacingOccurrencesOfString("\"", withString: "")
var newString2 = newString.stringByReplacingOccurrencesOfString("\n", withString: " ")
var arrayWithoutQOutes = newString2.characters.split{$0 == " "}.map(String.init)