unity中读取文件有两种方式:
1.Resources.Load("filename") as TextAsset;
2.www("file://"+filename);
这两种方式多平台适用。
但是有时候会出现同一个文件两种方式读取出来的字符串长度不同。
经过分析发现www读取出的字符串首位是65279。
这玩意是编码产生的标记,
Resources.Load应该处理过了,
www得自行解决。
public static string bom65279(string str_)
{
if (!string.IsNullOrEmpty(str_))
{
if ((int)str_.ToCharArray(0, 1)[0] == 65279)
{
str_ = str_.Substring(1);
}
return str_;
}
return null;
}