Ok, this is a little strange, but it works.
So, first you split your string into parts based on the character " :
string msg = "this string should have a comma here,\"but, there should be no comma in this bit\", and there should be a comma back at that and"; var parts = msg.Split('"');
then you need to join the line back with the symbol " after removing each comma in each other part:
string result = string.Join("\"", RemoveCommaFromEveryOther(parts));
The delete function looks like this:
IEnumerable<string> RemoveCommaFromEveryOther(IEnumerable<string> parts) { using (var partenum = parts.GetEnumerator()) { bool replace = false; while (partenum.MoveNext()) { if(replace) { yield return partenum.Current.Replace(",",""); replace = false; } else { yield return partenum.Current; replace = true; } } } }
To do this, you must enable the use directive for System.Collections.Generic .
source share