如何删除 <
之间的空格和回车符?和 >
?
**START BELOW THIS LINE***
<TestItem1Request>
<Username>admin</Username>
<Password>123abc..@!</Password>
<Item1>this is an item</Item1>
</TestItem1Request>
**END HERE **
我希望字符串结果如下...
</TestItem1Request><Username>admin</Username><Password>123abc..@!</Password><Item1>this is an item</Item1></TestItem1Request>
我该怎么做?
最佳答案
如果这是有效的 XML,您可以使用 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);
关于c# - 如何从字符串中删除回车符、换行符、空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6111712/