The examples of regular expressions on this page are probably good, but here is a solution without a regular expression:
string myString = "This is a string."; string myNewString = ""; char previousChar = ' '; foreach(char c in myString) { if (!(previousChar == ' ' && c == ' ')) myNewString += c; previousChar = c; }
source share