MikeMCSD
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
sb.Append(string.Format("{
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(", ", ","));
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('"', '\''));
I don't know but you can try:
(p.MetaKeywords.Replace('"', '\'')).Replace(", ", ",")
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"));
if you exactly wants to replace "comma with white space " by "comma" then do it as follows
-Kusala
sb.Append(string.Format("{0}{1}", p.MetaKeywords.Replace('"', '\'').Replace(", ", ","), ",Home Alarms"));
-Kusala
ASKER
thanks all
ASKER
p.MetaKeywords.Replace('"'