【发布时间】:2014-01-20 19:10:48
【问题描述】:
我真的迷路了,不知道我做错了什么。
StreamReader reader = new StreamReader (@"Destination.txt");
int i=0;
char[] word = new char[16];
While (reader.Peek().ToString() != " ")
{
word[i] = (char)reader.Read(); //This is when the debugger stops, after 16 iterations.
i++;
}
我肯定知道,在 txt 中,在最多 15 个字符之后总是有一个空格,所以它不应该超过单词数组的边界,但确实如此。我在这里做错了什么? 我使用 Tostring 的原因是 Peek 命令出于某种原因不断返回 Int。
【问题讨论】:
-
不确定,但尝试将
' '作为字符而不是字符串进行比较? -
那么你知道什么!?有效!我做了 (char) 而不是 tostring 并与 ' ' 相比,它有效!谢谢!