如何删除“\\\\ n”从一个字符串 [英] how to remove "\r\n" from a string
本文介绍了如何删除“\\\\ n”从一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hellow
从文本文件中,我读了2个字符串,每个字符串都是单行
Hellow
From a text file ,i read 2 strings each one is in single line
str1=sr.ReadLine();
str2=sr.ReadLine();
文本文件如下
scott
miller
i希望将str2附加到str1并在它们之间添加空格
the text file is as below
scott
miller
i want to attache str2 to str1 and add a space between them
str3=str1+ " " + str2;
因为 \\\\ n在每个字符串中,我没有得到我想要的,
\\\\ n必须删除
我怎么能减去来自str1和str2的\\\\ n
because of the "\r\n" in each string,i did not get whate i want,
"\r\n" must be removed
how can i subtract "\r\n" from both str1 and str2
推荐答案
如果您只想删除\\\\ n,请尝试替换:
If you only want to remove the \r\n, try Replace:
str1 = sr.ReadLine().Replace("\r\n", String.Empty);
str2 = sr.ReadLine().Replace("\r\n", String.Empty);
如果要删除所有尾随空格(如果有的话),包括\\\\ n,你可以使用 TrimEnd
:
If you want to remove all trailing whitespace (if there is any) including \r\n, you can use TrimEnd
:
str1 = sr.ReadLine().TrimEnd();
str2 = sr.ReadLine().TrimEnd();
这篇关于如何删除“\\\\ n”从一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文