使用StreamReader进行读取会在文件末尾给出不需要的字符 [英] Reading using StreamReader is giving unwanted character at end of the file
本文介绍了使用StreamReader进行读取会在文件末尾给出不需要的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码如下,
StreamReader sr = new StreamReader(tcpClient.GetSteram(),Encoding.Default,true);
string str = string.empty;
while循环,我在while循环内
str = sr.Readline();
我正在使用* .txt文件进行读取,假设* .txt文件的内容为如下
Kameshwar 1
Kamleshwar 2
Kamleshwar 3
因此,以上代码在文件内容的末尾给了我=符号. /span>
so the above code gives me '=' sign at the end of the files content.
仅供参考,我尝试更改编码类型,但仍未解决问题.
如果能为解决这个问题提供一些帮助,我将非常感激.
谢谢,
Kamleshwar
推荐答案
您可以在while循环中添加条件
you can add a condition in while loop
喜欢
if(str =="=")
if (str == "=")
{
//在这里什么也不做
}
其他
{
//您可以在此处编写逻辑
// you can write your logic here
}
这篇关于使用StreamReader进行读取会在文件末尾给出不需要的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文