如何在c#中读取文本文件中的多行? [英] how to read multi lines in text file in c#?

查看:59
本文介绍了如何在c#中读取文本文件中的多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢阅读检查文本是多行还是单行,然后我要阅读多行并转换为单行我该怎么做?

i like to read check the text has multi line or single line and then i am going to read that multi lines and convert into single line how can i do this?

推荐答案

您真的不需要检查,因为 File.ReadAllLines() 将始终返回一个字符串数组,而不管行数如何.您可以利用该行为,只需将返回的数组与您选择的分隔符连接起来.

You really do not need to check as File.ReadAllLines() will always return a string array regardless of the number of lines. You can leverage that behavior and simply join the returned array with your separator of choice.

string singleLine = string.Join(" ", File.ReadAllLines("filepath"));

这篇关于如何在c#中读取文本文件中的多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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