Created
May 24, 2015 01:29
-
-
Save khoa-le/751f0fac23ac760ffb66 to your computer and use it in GitHub Desktop.
Find and replace a character in a string in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
) | |
func main() { | |
str := " This string has many many spaces that need to be replaced " | |
fmt.Println(strings.Replace(str, " ", "", -1)) | |
str2 := " This string has much much spaces that need to be replaced " | |
fmt.Println(strings.Replace(str2, "much", "many", 2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment