【Swift】读取文本文件字符串
var str:NSString = NSString.stringWithContentsOfFile(_srcouceFilePath,encoding:NSUTF8StringEncoding,error:nil)
读取中文时首先要取得中文编码
var encode:NSStringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(CFStringEncodings.GB_18030_2000.toRaw()))
//现在的格式
var encode=CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(CFStringEncodings.GB_2312_80.rawValue))
var b="中国"
var data=b.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)
let cfEnc = CFStringEncodings.GB_18030_2000
let enc = CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(cfEnc.rawValue))
let a = NSString(data: data!, encoding: enc)!