用“"替换新行在C#中 [英] replace new lines with "" in C#

查看:89
本文介绍了用“"替换新行在C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将其转换为

  <translation>
      1 Sənədlər
    </translation>

到 使用C#在XML中<translation>1 Sənədlər</translation>.

to <translation>1 Sənədlər</translation> in XML using C#.

请帮助我.仅翻译标签.
我尝试过:

Please help me. Only translation tags.
I tried this:

XDocument xdoc = XDocument.Load(path);
        xdoc.Save("path, SaveOptions.DisableFormatting);

但是它不会删除<translation>标签之间的新行.

But it does not remove the new lines between <translation> tags.

推荐答案

代码中的新行由"\n"(可能还有"\r")确定.您可以简单地删除这些内容:

A new line is determined in the code by "\n" and possibly also "\r". You can simply remove these:

string xmlString = "<translation>\r\n1 Sənədlər\r\n</translation>"; // With the 'new lines'

xmlString = xmlString.Replace("\r", "").Replace("\n", "");

这将导致:

<translation>
1 Sənədlər
</translation>

成为:

<translation>1 Sənədlər</translation>

我希望这会有所帮助.

这篇关于用“"替换新行在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆