I
I
impressive172020-04-25 17:06:02
go
impressive17, 2020-04-25 17:06:02

How to take a substring in golang?

Let's say there is a string of 20 characters. How to cut it and leave only the first 10 characters in GO?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
uvelichitel, 2020-04-25
@uvelichitel

MyStringSlice := string([]rune(MyString)[:10])

M
Miit, 2020-04-25
@Miit

Probably the easiest way

fmt.Println("string"[:2])
// "st"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question