C# program to replace spaces with hyphen in a string

Views: 108   

Following program shows you how to replace spaces with hyphen in a string.
In this program we use .Replace to replace spaces with hyphen

using System;

class MainClass {
  public static void Main (string[] args) {
    string input = "Hello World";
    string result = input.Replace(" ", "-");
    Console.WriteLine("After replacing input string with - is: " + result);
  }
}

Output:

After replacing input string with - is: Hello-World
On By