trim Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/trim/ Sun, 23 Feb 2020 11:46:02 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://i0.wp.com/golangbyexamples.com/wp-content/uploads/2021/05/cropped-go_border-1.png?fit=32%2C32&ssl=1 trim Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/trim/ 32 32 159787465 Remove or Strip all white spaces from a string in Go (Golang) https://vikasboss.github.io/remove-all-white-spaces-string-golang/ https://vikasboss.github.io/remove-all-white-spaces-string-golang/#respond Sun, 23 Feb 2020 11:45:57 +0000 https://vikasboss.github.io/?p=1460 strings.ReplaceAll function can be used to trim all white spaces from a string in Golang. Below is the signature of the function s(first argument) is the input string old(second argument) is the...

The post Remove or Strip all white spaces from a string in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
strings.ReplaceAll function can be used to trim all white spaces from a string in Golang. Below is the signature of the function

func ReplaceAll(s, old, new string) string
  • s(first argument) is the input string
  • old(second argument) is the string that has to be replaced with new(third argument) string

Working Code:

package main

import (
    "fmt"
    "strings"
)

func main() {
    sample := " This is a sample string   "
    noSpaceString := strings.ReplaceAll(sample, " ", "")
    fmt.Println(noSpaceString)
}

Output:

Thisisasamplestring

The post Remove or Strip all white spaces from a string in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
https://vikasboss.github.io/remove-all-white-spaces-string-golang/feed/ 0 1460