獲取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

相關文章
相關標籤/搜索