【发布时间】:2013-05-14 19:42:23
【问题描述】:
所以我有一个我正在尝试实施的通用号码检查:
public static bool isNumberValid(string Number)
{
}
我想读取文本文件的内容(仅包含数字)并检查每一行的数字并使用isNumberValid 验证它是有效数字。然后我想将结果输出到一个新的文本文件,我已经到了这一步:
private void button2_Click(object sender, EventArgs e)
{
int size = -1;
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
string file = openFileDialog1.FileName;
try
{
string text = File.ReadAllText(file);
size = text.Length;
using (StringReader reader = new StringReader(text))
{
foreach (int number in text)
{
// check against isNumberValid
// write the results to a new textfile
}
}
}
catch (IOException)
{
}
}
}
如果有人可以提供帮助,有点卡住了?
文本文件在一个列表中包含多个数字:
4564
4565
4455
等等
我要写的新文本文件只是末尾附加了真或假的数字:
4564 对
【问题讨论】:
-
数字之间有某种分隔吗?输入文件中的一行是如何格式化的?
-
要写入新文件的结果是什么?
-
true or false,文本文件只是一个数字列表,每行都有相同数量的数字。将更新答案。
标签: c# io openfiledialog