How to replace more than a space in a string with some special character in c#

Viewed 192

How to replace more than a space in a string with some special character in c#?

I have a string as

Hi I  am new  here. Would   you    please help    me?

I want output as

Hi I$am new$here. Would$you$please help$me?

I tried

string line=@"Hi I  am new  here. Would   you    please help    me?";
string line1 = Regex.Replace(line,@"[\s\s]+","$");
Console.WriteLine(line1);

but I am getting output as

Hi$I$am$new$here.$Would$you$please$help$me?

Could you please tell me where am I going wrong?

3 Answers
Related