一切正常,只是它不读取特殊字符。我的文件“a.text”包含以下内容:
"ANBOCPDQERFSGTHUIVJWKXLYMZNAOBPCQDRESFTGUHVIWJXKYLZManbocpdqerfsgthuivjwkxlymznaobpcqdresftguhviwjxkylzm05162738495061728394<:>;(,).[?] {'}"/~\!|@_#+$-%*^=&:<;>,(.)?[
]'{"}~/!\@|#_$+%-^*&="
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication12
{
class Tester
{
static void Main(string[] args)
{
FileStream fs = new FileStream(@"d:\a.txt", FileMode.Open, FileAccess.Read);
string s = "aDFn3&5(09@Df0!/";
string c1 = "";
string c2 = "";
string c3 = "";
byte[] text2 = new byte[1];
byte[] text1;
int i,j,k=0;
while (k<16)
{
c1 = s.Substring(k, 1);
if (Regex.IsMatch(c1, @"^[A-Z]+$"))
{
i = 26;
j = 6;
fs.Seek(0, SeekOrigin.Begin);
}
else if (Regex.IsMatch(c1, @"^[a-z]+$"))
{
i = 26;
j = 6;
fs.Seek(182, SeekOrigin.Begin);
}
else if (Regex.IsMatch(c1, @"^[0-9]+$"))
{
i = 10;
j = 10;
fs.Seek(364, SeekOrigin.Begin);
}
else
{
i = 32;
j = 10;
fs.Seek(-352, SeekOrigin.End);
}
while(i>0)
{
fs.Read(text2, 0, 1);
c2 = System.Text.Encoding.Default.GetString(text2);
if (c1 == c2)
{
Console.Write(c2);
break;
}
fs.Seek(j, SeekOrigin.Current);
i--;
}
text1 = new byte[j];
fs.Read(text1, 0, j);
c3 = System.Text.Encoding.Default.GetString(text1);
Console.Write(c3);
Console.WriteLine();
k++;
}
}
}
}
我在尝试读取特殊字符并进行比较的输出中出现空格。我猜输入 c2 字符串的编码是问题所在,但我尝试了所有编码类型,UTF8、UNICODE、UTF7、UTF32 只是为了看到任何帮助。
帮我解决这个问题,所有回复表示赞赏。