阅读每行串线在C# [英] Reading a string line per line in C#

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

问题描述

可能重复:结果
在.net中?

我想读出并解释每行串线。我看了看StringReader类,但我需要找出当我在最后一行。这里是什么我试图完成一些伪代码:(!stringReaderObject.atEndOfStream())

I'm trying to read out and interpret a string line per line. I took a look at the StringReader class, but I need to find out when I'm on the last line. Here's some pseudocode of what I'm trying to accomplish:

while (!stringReaderObject.atEndOfStream()) {
    interpret(stringReaderObject.readLine());
}



是否有人知道如何做到这一点?

Does somebody know how to do this?

谢谢!

伊万

推荐答案

如果您正在从文件读取它,它是容易做只是做:

If you are reading it in from a file, it is easier to do just do:

foreach(var myString in File.ReadAllLines(pathToFile))
    interpret(myString);

如果您是从别的地方得到的字符串(Web服务类等)更简单刚刚拆分字符串:

If you are getting the string from somewhere else (a web service class or the like) it is simpler to just split the string:

foreach(var myString in entireString.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
    interpret(myString);

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

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