Skip to content
Go

strings API Reference

Go strings package — functions for manipulating UTF-8 strings.

By EZ4Code Team

strings

Package strings implements simple functions to manipulate UTF-8 encoded strings.

strings.Contains(s, substr string) bool

Return true if substr is within s.

Returns: bool

strings.HasPrefix(s, prefix string) bool

Return true if s begins with prefix.

Returns: bool

strings.HasSuffix(s, suffix string) bool

Return true if s ends with suffix.

Returns: bool

strings.Index(s, substr string) int

Return the index of the first instance of substr in s, or -1 if not present.

Returns: int

strings.Split(s, sep string) []string

Split s into substrings separated by sep. Returns []string.

Returns: []string

strings.Join(elems []string, sep string) string

Concatenate the elements of elems with sep between each.

Returns: string

strings.Replace(s, old, new string, n int) string

Return s with the first n non-overlapping instances of old replaced by new. n < 0 means no limit.

Returns: string

strings.ToUpper(s string) string

Return s with all Unicode letters mapped to upper case.

Returns: string

strings.ToLower(s string) string

Return s with all Unicode letters mapped to lower case.

Returns: string

strings.Trim(s, cutset string) string

Return s with all leading and trailing characters in cutset removed.

Returns: string

More Go API References