我一直在尝试让我的程序替换二进制文件中的 unicode。用户输入要查找的内容,程序将查找并用特定的字符串(如果可以找到的话)替换它。
我四处搜寻,但没有找到具体的信息,我想要的是这样的:
string text = File.ReadAllText(path, Encoding.Unicode);
text = text.Replace(userInput, specificString);
File.WriteAllText(path, text);
Run Code Online (Sandbox Code Playgroud)
但任何以类似方式工作的东西都应该足够了。但是,使用它会导致文件更大且无法使用。
我用:
int var = File.ReadAllText(path, Encoding.Unicode).Contains(userInput) ? 1 : 0;
if (var == 1)
{
//Missing Part
}
Run Code Online (Sandbox Code Playgroud)
用于检查文件是否包含用户输入的字符串(如果重要)。