Remove   in string

(Miha) #1


what is the best option to remove "   " in string? I am getting this in text and I need to remove it.


(catacombs) #2

You can use the ReplaceAll function from the strings library:

package main

import (

func main() {
	fmt.Println(strings.ReplaceAll("Hello there, friends", " ", ""))

(Ashish Shekar) #3

Ok, it depends on where exactly you want to remove this space character from.

  1. - to remove from the right
  2. - to remove from the left
  3. - to remove from anywhere inside a string

(Yamil Bracho) #4

You can also use string.Trim which remove leading and trailing spaces (&nbsp)