H
H
Hugose2017-07-02 17:04:50
go
Hugose, 2017-07-02 17:04:50

GoLang working with strings?

I'm trying to cut out spaces and letters from a string, I managed to cut out the letters using Trim, but I can't figure out how to get the spaces.
package main
import (
"fmt"
"strings"
)

func main() {

str := "5 000 000 шт"
str2 := strings.Trim(str, " шт")

fmt.Println(str2)

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2017-07-02
@Hugose

You can use strings.Replace

str := "5 000 000 шт"

str2 := strings.Replace(str, " ", "", -1)
// str2 будет содержать: "5000000шт"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question