Ben Chuanlong Du's Blog

It is never too late to learn.

Manipulate Strings Using the `strings` Module in Golang

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

In [1]:
import "strings"
In [5]:
strings.Index("go gopher", "go")
Out[5]:
0
In [6]:
strings.Index("go gopher", "roden")
Out[6]:
-1
In [3]:
strings.LastIndex("go gopher", "go")
Out[3]:
3
In [4]:
strings.LastIndex("go gopher", "rodent")
Out[4]:
-1
In [2]:
strings.HasPrefix("International", "Inter")
Out[2]:
true
In [4]:
strings.HasSuffix("International", "national")
Out[4]:
true
In [3]:
strings.Join([]string{"a", "b", "c"}, ", ")
Out[3]:
a, b, c
In [3]:
strings.Replace("how are you", "how", "How", 1)
Out[3]:
How are you
In [4]:
strings.ReplaceAll("how are you", "how", "How")
Out[4]:
How are you
In [2]:
strings.Split("a", "a")
Out[2]:
[ ]
In [3]:
strings.Split("abc", "\n")
Out[3]:
[abc]
In [5]:
strings.Split("how,are,you", ",")
Out[5]:
[how are you]
In [ ]:
 

Comments