Jessica Jessica - 6 months ago 26
C# Question

How can I replace a space in a string with an underscore in C#?

I have strings such as:

var abc = "Menu Link";

Is there a simple way I can change the space to an underscore?


If you want to do it in place:

abc = abc.Replace(" ", "_");

Although do realize a new string instance will be created; it's not actually done in the same memory location - String is an immutable type.