【发布时间】:2012-09-11 14:54:25
【问题描述】:
我制作了这个包含列表视图的 exe,所以当我打开二进制文件时,它会在一列中显示文本指针,在另一列中显示文本字符串。
我设法显示指针,使用“for循环”,但我不知道如何使用循环显示文本字符串,所以我想使用的是循环指针,显示它指向的文本,并在每个文本之后停止在 00 00。
而here 是二进制文件结构的示例。
二进制文件的前4个字节是指针/字符串数量,接下来的4个字节*第1个4个字节是指针,其余是文本字符串,每个字符串用00 00分隔,都是Unicode。
那么任何人都可以帮助我如何在字符串列中显示每个指针的字符串吗?
编辑:这是打开二进制文件的按钮的代码:
private void menuItem8_Click(object sender, EventArgs e)
{
textBox1.Text = "";
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Open File";
ofd.Filter = "Data Files (*.dat)|*.dat|All Files (*.*)|*.*";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
MessageBox.Show("File opened Succesfully!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
path = ofd.FileName;
BinaryReader br = new BinaryReader(File.OpenRead(path));
int num_pointers = br.ReadInt32();
textBox1.Text = num_pointers.ToString();
for (int i = 0; i < num_pointers; i++)
{
br.BaseStream.Position = i * 4 + 4;
listView1.Items.Add(br.ReadUInt32().ToString("X"));
}
br.Close();
br = null;
}
ofd.Dispose();
ofd = null;
}
【问题讨论】:
-
花时间和麻烦在此处发布您的代码(相关部分)。
-
添加了代码,如果你需要什么,请评论。
-
您是否发现将字节数组转换为字符串很困难?
-
是的,尤其是当有很多字符串时,我只需要一种方法来遍历指针列,并在第二列中显示每个指针指向的字符串。谢谢。
标签: c# .net file listview binary