我有来自TextBox1
的数据00 00 00 4E FF 53 4D 42 25 00 00 00 00 18 01 28 ...N.SMB%......(
00 00 00 00 00 00 00 00 00 00 00 00 00 08 12 8B ................
01 08 7E 31 11 00 00 05 00 00 00 00 00 00 00 02 ..~1............
我尝试在结果TextBox2
上将其更改为这样...N.SMB%......(
................
..~1............
我尝试过这个功能*。删除但只删除第一行,但不删除第二行等。有人能帮助我吗?
我使用此代码
string test = rtText1.Text;
rtText2.Text = test.Remove(0, 48);
然后这个结果rtText2
...N.SMB%......(
00 00 00 00 00 00 00 00 00 00 00 00 00 08 12 8B ................
01 08 7E 31 11 00 00 05 00 00 00 00 00 00 00 02 ..~1............
如何在每行上创建命令“ test.Remove(0,48); ”?还是有其他功能?
答案 0 :(得分:1)
很难根据你发布的内容确切地说出你需要什么,但正则表达式可能在这里运作良好:
TextBox2.Text = System.Text.RegularExpressions.Regex.Replace(
TextBox1.Text,
@"^.{49}",
"",
RegexOptions.Multiline );
这只是用空字符串替换每行的前49个字符。
答案 1 :(得分:0)
在我看来,好像你正试图删除右边任何字符串的十六进制表示。
这对我有用:
// Initial data
string Data = @"00 00 00 4E FF 53 4D 42 25 00 00 00 00 18 01 28 ...N.SMB%......(
00 00 00 00 00 00 00 00 00 00 00 00 00 08 12 8B ................
01 08 7E 31 11 00 00 05 00 00 00 00 00 00 00 02 ..~1............";
// An array containing each line of data
string[] lines = Data.Split('\n');
Data = "";
// Loop for each line, removing each "byte" + it's space, plus the trailing space
for (int i = 0; i < lines.Length; i++)
{
Data += lines[i].Remove(0, (3 * 16) + 1);
if (i != lines.Length - 1)
Data += "\r\n";
}
Console.Write(Data);
这是输出:
...N.SMB%......(
................
..~1............