I
I
Ivan2021-03-25 15:58:52
go
Ivan, 2021-03-25 15:58:52

How to crop text in GO?

There is a line like this: "UserName: Vasya Pupkin". How to remove from this line UserNаme:and leave only Vasya Pupkin? All of these trims either don't work or don't work properly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Pavlyuk, 2021-03-25
@Djonson86

Trims work quite well https://play.golang.org/p/31OXind1eyt

str := "UserName: Vasya Pupkin"
result := strings.TrimPrefix(str, "UserName: ")
fmt.Println(result)

1
12rbah, 2021-03-25
@12rbah

https://play.golang.org/p/d3A1Hjtd-t3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question