阅读文字 [英] reading in text

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

问题描述

我想知道是否可以在文本文件中读取其他数据类型,而不是字符串。我想把它读作某种处理数字的类型,

就像是double,或者浮动。

解决方案

Christine <章******* @ discussions.microsoft.com>写道:

我想知道是否可以在文本文件中读取其他数据类型而不是字符串。我想把它读作一种处理数字的类型,
像double或float。




你把每个部分都读成一个字符串(或者整行作为一个字符串,然后

分解),然后调用适当的Parse方法(或

Doule.TryParse)。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复该群组,请不要给我发邮件


我的问题是它无法在我的机器上运行。我不知道

为什么,但是在解析文本时我的代码运行不正确。

我让其他人运行的代码完全相同它适用于

但不适合我。出于某种原因,当我解析文本时,我仍然得到空值的b $ b。但就像我说的那样,完全相同的代码,复制和粘贴,对其他人的工作方式不同。所以我试图找出如何解决这个问题。


" Jon Skeet [C#MVP]"写道:

Christine< Ch ******* @ discussion.microsoft.com>写道:

我想知道是否可以在文本文件中读取其他数据类型而不是字符串。我想把它读作某种处理数字的类型,
像double或float。



你把每个部分都读成一个字符串(或整行作为一个字符串)字符串然后
分解),然后调用适当的Parse方法(或
Doule.TryParse)。

-
Jon Skeet - < sk ***@pobox.com>
http://www.pobox.com / ~siget
如果回复小组,请不要给我发邮件



Christine< Ch **** ***@discussions.microsoft.com>写道:

我的问题是它无法在我的机器上运行。我不知道为什么,但是我的代码在解析文本时运行不正确。
我让其他人运行完全相同的代码,它适用于
他们但不适合我。由于某种原因,当我解析文本时,我仍然得到空值。但就像我说的那样,完全相同的代码,复制和粘贴,对其他人来说是不同的。所以我试图找出如何解决这个问题。




你不能得到一个空的东西。一个int或一个double的值。


你能发一个简短但完整的程序来演示

问题,即使它只是在你的电脑?

http://www.pobox.com/~skeet/csharp/complete.html 了解详情

我的意思是什么。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件


I was wondering if it is possible to read in a text file as a data type other
than string. I would like to read it in as some type that handles numbers,
like double, or float.

解决方案

Christine <Ch*******@discussions.microsoft.com> wrote:

I was wondering if it is possible to read in a text file as a data type other
than string. I would like to read it in as some type that handles numbers,
like double, or float.



You read each part as a string (or a whole line as a string and then
break it up), and then call the appropriate Parse method (or
Doule.TryParse).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


My problem with that is that it is not working on my machine. I do not know
why, but my code is not running correctly when it comes to parsing the text.
I have had other people run the exact same code that I have and it works for
them but not for me. For some reason when I parse the text, I still get
empty values. But like I said, the exact same code, copied and pasted, works
differently for other people. So I am trying to find out how to get around
this problem.

"Jon Skeet [C# MVP]" wrote:

Christine <Ch*******@discussions.microsoft.com> wrote:

I was wondering if it is possible to read in a text file as a data type other
than string. I would like to read it in as some type that handles numbers,
like double, or float.



You read each part as a string (or a whole line as a string and then
break it up), and then call the appropriate Parse method (or
Doule.TryParse).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



Christine <Ch*******@discussions.microsoft.com> wrote:

My problem with that is that it is not working on my machine. I do not know
why, but my code is not running correctly when it comes to parsing the text.
I have had other people run the exact same code that I have and it works for
them but not for me. For some reason when I parse the text, I still get
empty values. But like I said, the exact same code, copied and pasted, works
differently for other people. So I am trying to find out how to get around
this problem.



You can''t get an "empty" value for an int or a double though.

Could you post a short but complete program which demonstrates the
problem, even if it only demonstrates it on your computer?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


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

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