将下面的字符串转换为NSArray

时间:2017-01-04 12:16:39

标签: ios swift2 swift2.3

实际上我从远程文件中获取此数据

http://appsnurture.com/csv/sample.csv

"\"030506941\"\n\"032752389\"\n\"033415694\"\n\"035010096\"\‌​n\"035010106\"\n\"03‌​5010108\"\n\"0350101‌​18\"\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的选项。

1 个答案:

答案 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)