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 str:NSString = NSString.stringWithContentsOfFile(_srcouceFilePath,encoding:encode,error:nil)
http://blog.sina.com.cn/s/blog_8a323e5c0101i3gz.html
转换成 字符编码
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)!