Go: Retrieve a string from between two characters or other strings

后端 未结 7 1687
有刺的猬
有刺的猬 2021-01-05 14:47

Let\'s say for example that I have one string, like this:

Hello World!

What Go code would be able to extract Hel

7条回答
  •  太阳男子
    2021-01-05 15:30

    In the strings pkg you can use the Replacer to great affect.

    r := strings.NewReplacer("

    ", "", "

    ", "") fmt.Println(r.Replace("

    Hello World!

    "))

    Go play!

提交回复
热议问题