Go language program to replace spaces with hyphen in a string

Views: 150   

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

package main

import "fmt"
import "strings"

func main() {

  var input = "Hello World" 
  var result string
  result = strings.Replace(input," ", "-", -1)
  fmt.Println("After replacing input string with - is: " , result)
}

Output:

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