How to replace multiple spaces with single space?
问题 I am developing web app using C#. I want to replace multiple spaces with single space in between string. I tried with normal string replace function, but it was not helpful. It is possible with Regular Expression, but I don't have clear idea about that. Please provide a example code for the following string: Actual String: Have a Nice Day ! !! Needed: Have a Nice Day !!! 回答1: You can match the following: @"\s+" and replace with: " " Regex.Replace("Have a Nice Day ! !!", @"\s+", " "); 回答2: See