如何从一个字符串中删除回车,换行,空格 [英] how to remove carriage returns, newlines, spaces from a string

查看:545
本文介绍了如何从一个字符串中删除回车,换行,空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么删除空格,从回车之间<和>

how do I remove the spaces, carriage returns from in between < and >

**START BELOW THIS LINE***

</TestItem1Request>
  <Username>admin</Username>
  <Password>123abc..@!</Password>
  <Item1>this is an item</Item1>
</TestItem1Request>

**END HERE **



我要的字符串结果结束了如下...

I want the string result to end up as the following...

</TestItem1Request><Username>admin</Username><Password>123abc..@!</Password><Item1>this is an item</Item1></TestItem1Request>



我如何做到这一点?

How do I do this?

推荐答案

如果这是有效的XML,你可以使用的 SaveOptions.DisableFormatting枚举

If this is valid XML you could use the SaveOptions.DisableFormatting enumeration:

string input = @"<TestItem1Request>
  <Username>admin</Username>
  <Password>123abc..@!</Password>
  <Item1>this is an item</Item1>
</TestItem1Request>";

string result = XElement.Parse(input).ToString(SaveOptions.DisableFormatting);
Console.WriteLine(result);

这篇关于如何从一个字符串中删除回车,换行,空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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