0

这是我获取文本的方式:

switch(lsel) {
    case 0:
        luafile = "lua/example.lua";
        break;
    case 1:
        luafile = "lua/example2.lua";
        break;
    }
ifstream f(luafile);
f >> noskipws;  //don't want to skip spaces !
vector<unsigned char> v(
    (istream_iterator<unsigned char>(f))
    , (istream_iterator<unsigned char>()));
LBytes lexing = LBytes(bytes, 2);
lexing += lselect;
lexing += LBytes(v.data(), v.size());
//f.close();
return lexing;

然后我在 C# 中处理它:

int docnumber = BitConverter.ToInt32(Core.ncon.ArrayRead, 2);
Log(docnumber.ToString());
char[] valx = new char[Core.ncon.ArrayReadSize - 2 - sizeof(int)];
Array.Copy(Core.ncon.ArrayRead, 2, valx, 0, Core.ncon.ArrayReadSize - 2 - sizeof(int));
Core.lua[docnumber] = new string(valx);

并放入 RichTextBox

private void confListBox_SelectedIndexChanged(object sender, EventArgs e) {
    if (confListBox.SelectedIndex < 10) {
        string one = Core.lua[confListBox.SelectedIndex];
        this.luaTextBox.Text = one;
        }

现在一个包含字符串:

"\0\0\0\0io.write(\"Please enter your name: \")\n-- name = io.read() -- read input from user\nname = \"someone\"\nprint (\"Hi \" .. name .. \", enjoy hacking with Lu"

和文本将是""

这些\0\0\0\0东西是从哪里来的?

4

1 回答 1

1

似乎您在文本前面添加了一些来自与文件不同来源的内容:

LBytes lexing = LBytes(bytes, 2);
lexing += lselect;
lexing += LBytes(v.data(), v.size());

我怀疑前两行贡献了零。

于 2012-11-19T11:35:23.183 回答