Hi,
I want an regular expression to eliminate the white space from an xml file having style tags.
Eg: "Font-Style : italic" should be converted to "Font-Style:italic"
How can i achieve this?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Feb 7, 2013, 5:07 AM EST
For example, this code will get rid of white space for any tag which ends with '-Style':
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 7, 2013, 5:58 PM EST
try...
var myString = "Font-Style : italic";
myString = Regex.Replace(myString, @"[ ]", string.Empty, RegexOptions.Multiline);
hope this will help you.
Salma Siddiqa11 reputationPosted Feb 7, 2013, 6:32 PM EST
My requirement is to search for " : " in an xml file and remove the space.
Salma Siddiqa11 reputationPosted Feb 7, 2013, 8:50 PM EST
Thank you for your replies .
I could resolved this using the following:
string output=new StringBuilder(Regex.Replace(input, @"\s*:\s*", ":").Trim());
VulpesRank #55 · 29.2K reputationPosted Feb 8, 2013, 12:00 AM EST
However, there's no need to use it anyway as this should work fine:
string output = Regex.Replace(input, @"\s*:\s*", ":").Trim();