获取TXT文件,解决读取TXT乱码问题,查找所输入字是否在TXT文件中,

       

/// <summary>
/// 查看是否存在
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool Illegalchar(string str)
{
LoadIllegalchar();//查找到应该过滤的文件
string[] LimitedChars = LimitedChar.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries); //去掉空字符串
foreach (string _lim in LimitedChars)
{
int _pos = str.IndexOf(_lim);
if (_pos >= 0)//若是>=0 那么此字在字符串中位置
{
return false;
}
}
return true;
}spa

/// <summary>
/// 获取到过滤字TXT,将其放入到字符串中
/// </summary>
public static void LoadIllegalchar()
{
    string fileName = AppDomain.CurrentDomain.BaseDirectory.ToString() + "Filter.txt";
    if (File.Exists(fileName))
    {字符串

     //这句话就不乱码了;string

     StreamReader sr = new StreamReader(fileName , Encoding.GetEncoding("gb2312")); 
     LimitedChar = sr.ReadLine();
    }
}it

相关文章
相关标签/搜索