[英]C# Removing Tabs from Readline Input
I am inputting lines using the StreamReader's ReadLine. 我正在使用StreamReader的ReadLine输入行。 However for user friendliness in terms of reading the files outside of the program, I want to add tabbing.
但是,为了方便用户阅读程序外的文件,我想添加制表符。 But I need to remove any tabbing when the files are being read in the program.
但是在程序中读取文件时,我需要删除所有制表符。
How can this be achieved? 如何做到这一点? I have considered using Trim but I don't know if that will work.
我已经考虑过使用Trim,但是我不知道是否行得通。
Use string.Trim
with the specified characters if you want starting and trailing tabs: 如果要开始和尾随制表符,请使用具有指定字符的
string.Trim
:
var trimmed = streamReader.ReadLine().Trim('\t');
Or Regex.Replace
if tabs are also in the middle: 或
Regex.Replace
如果标签也位于中间则Regex.Replace
:
string trimmed = Regex.Replace(lineWithTabs, @"\t", "");
You can use String.Replace
: 您可以使用
String.Replace
:
string fileContent = File.ReadAllText("path");
fileContent = fileContent.Replace('\t', ' ');
Of course that works also for every line returned by ReadLine
. 当然,这也适用于
ReadLine
返回的每一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.