很奇怪的问题,我这样写
string[] sentences =
{
"你",
"x"
};
bool find = false;
string sPattern = this.content.Text;
foreach (string s in sentences)
{
if (System.Text.RegularExpressions.Regex.IsMatch(sPattern,s))
{
//找到了
}
else
{
//没有找到
}
然后我在content里提交“你”,他能够识别出来,但是如果我用下面的方法
FileStream fs = new FileStream(Server.MapPath(".")+"\\test1.txt",FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs);
string[] words= sr.ReadToEnd().Split('|');
bool find = false;
string sPattern = this.content.Text;
foreach (string s in words)
{
if (System.Text.RegularExpressions.Regex.IsMatch(sPattern,s))
{
//找到了
}
else
{
//没有找到
}
test1.txt里面的内容为 你|x
但是问题出现了,我无论提交什么中文他都是别不了,但是英文却是可以
请问是怎么回事?
string[] sentences =
{
"你",
"x"
};
bool find = false;
string sPattern = this.content.Text;
foreach (string s in sentences)
{
if (System.Text.RegularExpressions.Regex.IsMatch(sPattern,s))
{
//找到了
}
else
{
//没有找到
}
然后我在content里提交“你”,他能够识别出来,但是如果我用下面的方法
FileStream fs = new FileStream(Server.MapPath(".")+"\\test1.txt",FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs);
string[] words= sr.ReadToEnd().Split('|');
bool find = false;
string sPattern = this.content.Text;
foreach (string s in words)
{
if (System.Text.RegularExpressions.Regex.IsMatch(sPattern,s))
{
//找到了
}
else
{
//没有找到
}
test1.txt里面的内容为 你|x
但是问题出现了,我无论提交什么中文他都是别不了,但是英文却是可以
请问是怎么回事?
StreamReader sr = new StreamReader(fs);
没有加上encoding读取的方式
这样就能识别中文了
StreamReader sr = new StreamReader(fs,System.Text.Encoding.GetEncoding("GB2312"));