使用Replace()用字符串替换字节

时间:2013-07-02 19:29:38

标签: c# winforms

是否可以在此方法中将字节替换为字符:

byte[] sttrings = new byte[pntrs[i + 1] - pntrs[i]];
stream.Position = pntrs[i];
stream.Read(sttrings, 0, sttrings.Length);
Strs[i] = Encoding.GetEncoding("SHIFT-JIS").GetString(sttrings).Split('\0')[0].Replace("[FF00]", "/et");

其中0x00FF(在十六进制编辑器中为FF 00)是我要用" / et"替换的字节。

1 个答案:

答案 0 :(得分:2)

假设您正在寻找unicode char 0x00FF(ÿ),您只需要使用Unicode escape character`\ uxxxx。

byte[] sttrings = new byte[pntrs[i + 1] - pntrs[i]];
stream.Position = pntrs[i];
stream.Read(sttrings, 0, sttrings.Length);
Strs[i] = Encoding.GetEncoding("SHIFT-JIS").GetString(sttrings).Split('\0')[0].Replace("[\u00FF]" , "/et");

如果您真的想要替换字节值,则可以使用String constructor that takes in a char[]

string replacementString = new String(new char[] {'[', '\0', (char)0xFF, ']'});