C#从文本文件中读取制表符作为设置 [英] C# reading a tab character as a setting from text file
问题描述
Good Day,我今天加入了。
Good Day, i joined today.
我在文本文件中有一个设置。
I have a setting in text-file.
logSeparator = \t
logSeparator=\t
这将在启动期间读入Properties.Settings(字符串)。
this will be read into Properties.Settings(string) during start-up.
当我将其读取为字符串时,它将变为 \\t
when I read this into a string it will become "\\t"
所以我有一个临时性的解决办法来保持正常工作:
so I have a temporary fix to keep things working:
if (Properties.Settings.Default.logSeparator == "\\t") { //trim \t
Properties.Settings.Default.logSeparator = "\t";
Properties.Settings.Default.Save();
}
应该有一些简单的方法可以清理此字符串并使它作为一个字符
there should be some easy way to clean this string and make it as a char
\t,现在,如果最终用户决定开始使用 \r作为分隔符
"\t", now, if enduser decides to start using for example "\r" as separator
字符不起作用。
我正在寻找简单的东西:
string_name.Replace( \\ , \);
//(这不起作用)
I am looking something easy like this: string_name.Replace("\\", "\"); //(this does not work)
请帮助,我敢肯定必须有一种简单而干净的方法,但是花了很多时间
please help, I am sure there has to be easy and clean way of doing this, however spent quite a time with google trying to figure this out and couldn't find anything.
推荐答案
如果您仅使用string.Format(logSeparator),将其转换。您无需进行剥离。我想您会在监视窗口中看到的是字符序列的转义版本。也就是说,字符串\t将在监视窗口中显示为\\t,以区别于制表符-字符串中实际上没有两个反斜杠。
If you just use string.Format(logSeparator) it will convert it. You don't need to do your \ stripping. I'm guessing what you are seeing in the watch window will be the escaped version of the character sequence. i.e. the string \t will show in the watch window as \\t to differentiate it from a tab character - it doesn't actually have two backslashes in the string.
这篇关于C#从文本文件中读取制表符作为设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!