Link to home
Start Free TrialLog in
Avatar of MikeMCSD
MikeMCSDFlag for United States of America

asked on

Take the spaces out of this string after the comma.

In the field "MetaKeywords" below :

sb.Append(string.Format("{0}{1}", p.MetaKeywords.Replace('"', '\''), ",Home Alarms"));

it has a value like : "dome cam, dummy cam, fake Surveillance, fake security, cameras"


I want to remove the space after the commas, like : "dome cam,dummy cam,fake Surveillance,fake security,cameras"


How can this be done in C#? thanks
ASKER CERTIFIED SOLUTION
Avatar of X Layer
X Layer
Flag of Slovenia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MikeMCSD

ASKER

thanks . . is it possible to add it to the replace I have already?

 p.MetaKeywords.Replace('"', '\''), ", . . .
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
so it would be something like so:


string s = "dome cam,     dummy cam, fake Surveillance, fake security, cameras";

            RegexOptions options = RegexOptions.None;
            Regex regex = new Regex(@"[ ]{2,}", options);
            string x = regex.Replace(s, @" ");


            Response.Write(x.Replace(", ", ","));

Open in new window

yes to add in your replace just do:
string s = "dome cam,     dummy cam, fake Surveillance, fake security, cameras";

            RegexOptions options = RegexOptions.None;
            Regex regex = new Regex(@"[ ]{2,}", options);
            string x = regex.Replace(s, @" ");


            Response.Write(x.Replace(", ", ",").Replace('"', '\''));

Open in new window

I don't know but you can try:
(p.MetaKeywords.Replace('"', '\'')).Replace(", ", ",")

Open in new window

so it would be like so:
RegexOptions options = RegexOptions.None;
            Regex regex = new Regex(@"[ ]{2,}", options);
            string x = regex.Replace(p.MetaKeywords, @" ").Replace(", ", ",").Replace('"', '\'');

            sb.Append(string.Format("{0}{1}", x, ",Home Alarms"));

Open in new window

if you exactly wants to replace "comma with white space " by "comma" then do it as follows

sb.Append(string.Format("{0}{1}", p.MetaKeywords.Replace('"', '\'').Replace(", ", ","), ",Home Alarms"));

Open in new window


-Kusala
thanks all