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?
In the Find box hold down the Alt key and type 0 1 0 for the line feed and Alt 0 1 3 for the carriage return. They can now be replaced with whatever you want.
Use the String. replace() method to remove all whitespace from a string, e.g. str. replace(/\s/g, '') . The replace() method will remove all whitespace characters by replacing them with an empty string.
Removes all carriage return values ( Chr(13) ) from a string.
replaceAll("\\n", ""); s = s. replaceAll("\\r", ""); But this will remove all newlines. Note the double \ 's: so that the string that is passed to the regular expression parser is \n .
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With