Reputation: 42464
I have string like "First Last Name"
I want to replace empty spaces to % like
"First%Last%Name"
How to replace consecutive spaces to single %?
Upvotes: 4
Views: 109
Reputation: 217341
var result = string.Join("%",
str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
Upvotes: 1
Reputation: 838696
You can do it with a regular expression:
str = Regex.Replace(str, " +", "%");
Upvotes: 6