从文件中读取整数 [英] read integers from files

查看:47
本文介绍了从文件中读取整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成了包含随机数的文本文件(使用for循环),这些数字以 空格编号空间 <的形式存储在文本文件中/ b>。我需要读取每个10位数的整数(如8210347655)。我很头疼,看到它很麻烦,请任何人帮助我。



问候......

I have generated text file containing random numbers (using for loop), and these numbers are stored in the text file in the form space number space. I need to read integers each of 10-digit (as 8210347655). I'm very headache and seeing it a very trouble, please can anyone help me.

regards...

推荐答案

0)一次读取一个字符

1)将非SPACE附加到StringBuilder(或类似的,我现在看到这不是.net问题)

2)当你到达一个空格时,在StringBuilder的内容上使用Int32.TryParse

3)然后将StringBuilder的长度设置为零

4)当你到达终点时,再做一次TryParse



也可能需要一些错误处理。
0) Read one character at a time
1) Append the non-SPACEs to a StringBuilder (or similar, I see now this isn't a .net question)
2) When you reach a SPACE, use Int32.TryParse on the content of the StringBuilder
3) Then set the StringBuilder's Length to zero
4) When you reach the end, do one more TryParse

Some error handling might be necessary as well.


这篇关于从文件中读取整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆