下载unix \ n文本文件,转换为\\\ n非unix? [英] Downloading unix \n text files, convert to \r\n non-unix?
问题描述
我正在从Unix系统下载带有\\\
换行符的文件,并将
存储到字符串中。我想将它转换为\\\ n \\ n \\ n $ $ $ $ b $ Windows的换行符。我知道StreamReader有一个Encoding属性,但是这个
并不是我需要的。我应该做一个String.Replace(),还是有一个
更好的解决方案?
Zytan
我应该做一个String.Replace(),还是有更好的解决方案?
String.Replace(" \ n"," \\\\ n")不起作用。它没有改变
任何东西。
Zytan
Zytan写道:
>我应该执行String.Replace(),还是有更好的解决方案?
String.Replace(" \ n"," \\\\ n)"不起作用。它没有改变任何东西。
应该。
string s =" A\\\
BB\\\
CCC";
Console.WriteLine(s.Length);
s = s.Replace(" \ n"," \\\\ n");
Console.WriteLine(s.Length);
为我打印8和10!
Arne
Arne Vajh?j写道:
Zytan写道:
>>我应该执行String.Replace(),还是有更好的解决方案?
String.Replace(" \ n"," \\\\ n)"不起作用。它没有改变任何东西。
它应该。
string s =" A\\\
BB\\\
CCC";
Console.WriteLine(s.Length);
s = s.Replace(" \ n"," \\\\ n");
Console.WriteLine(s.Length);
为我打印8和10!
但我认为:
string s =" A\\\
BB\\\
CCC";
Console.WriteLine(s.Length);
s = Regex.Replace(s,"(?<!\ r)\ n",Environment.NewLine);
Console.WriteLine(s.Length);
是更好的代码!
Arne
I am downloading a file with \n newlines from a Unix system, and
storing it to a string. I want to convert it to \r\n newlines for
Windows. I know the StreamReader has an Encoding attribute, but this
isn''t what I need. Should I do a String.Replace(), or is there a
better solution?
Zytan
Should I do a String.Replace(), or is there a better solution?
String.Replace("\n", "\r\n") doesn''t work. It doesn''t change
anything.
Zytan
Zytan wrote:>Should I do a String.Replace(), or is there a better solution?
String.Replace("\n", "\r\n") doesn''t work. It doesn''t change
anything.It should.
string s = "A\nBB\nCCC";
Console.WriteLine(s.Length);
s = s.Replace("\n", "\r\n");
Console.WriteLine(s.Length);
prints 8 and 10 for me !
Arne
Arne Vajh?j wrote:Zytan wrote:>>Should I do a String.Replace(), or is there a better solution?
String.Replace("\n", "\r\n") doesn''t work. It doesn''t change
anything.
It should.
string s = "A\nBB\nCCC";
Console.WriteLine(s.Length);
s = s.Replace("\n", "\r\n");
Console.WriteLine(s.Length);
prints 8 and 10 for me !But I think:
string s = "A\nBB\nCCC";
Console.WriteLine(s.Length);
s = Regex.Replace(s, "(?<!\r)\n", Environment.NewLine);
Console.WriteLine(s.Length);
is better code !
Arne
这篇关于下载unix \ n文本文件,转换为\\\ n非unix?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!