docs/stdlib-strings.md

Summary

Maintainability
Test Coverage

[//]: <> (Generated by ugodoc. DO NOT EDIT.)

# `strings` Module

## Functions

`Contains(s string, substr string) -> bool`

Reports whether substr is within s.

---

`ContainsAny(s string, chars string) -> bool`

Reports whether any char in chars are within s.

---

`ContainsChar(s string, c char) -> bool`

Reports whether the char c is within s.

---

`Count(s string, substr string) -> int`

Counts the number of non-overlapping instances of substr in s.

---

`EqualFold(s string, t string) -> bool`

EqualFold reports whether s and t, interpreted as UTF-8 strings,
are equal under Unicode case-folding, which is a more general form of
case-insensitivity.

---

`Fields(s string) -> array`

Splits the string s around each instance of one or more consecutive white
space characters, returning an array of substrings of s or an empty array
if s contains only white space.

---

`FieldsFunc(s string, f func(char) bool) -> array`

Splits the string s at each run of Unicode code points c satisfying f(c),
and returns an array of slices of s. If all code points in s satisfy
f(c) or the string is empty, an empty array is returned.

---

`HasPrefix(s string, prefix string) -> bool`

Reports whether the string s begins with prefix.

---

`HasSuffix(s string, suffix string) -> bool`

Reports whether the string s ends with prefix.

---

`Index(s string, substr string) -> int`

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

---

`IndexAny(s string, chars string) -> int`

Returns the index of the first instance of any char from chars in s, or
-1 if no char from chars is present in s.

---

`IndexByte(s string, c char|int) -> int`

Returns the index of the first byte value of c in s, or -1 if byte value
of c is not present in s. c's integer value must be between 0 and 255.

---

`IndexChar(s string, c char) -> int`

Returns the index of the first instance of the char c, or -1 if char is
not present in s.

---

`IndexFunc(s string, f func(char) bool) -> int`

Returns the index into s of the first Unicode code point satisfying f(c),
or -1 if none do.

---

`Join(arr array, sep string) -> string`

Concatenates the string values of array arr elements to create a
single string. The separator string sep is placed between elements in the
resulting string.

---

`LastIndex(s string, substr string) -> int`

Returns the index of the last instance of substr in s, or -1 if substr
is not present in s.

---

`LastIndexAny(s string, chars string) -> int`

Returns the index of the last instance of any char from chars in s, or
-1 if no char from chars is present in s.

---

`LastIndexByte(s string, c char|int) -> int`

Returns the index of byte value of the last instance of c in s, or -1
if c is not present in s. c's integer value must be between 0 and 255.

---

`LastIndexFunc(s string, f func(char) bool) -> int`

Returns the index into s of the last Unicode code point satisfying f(c),
or -1 if none do.

---

`Map(f func(char) char, s string) -> string`

Returns a copy of the string s with all its characters modified
according to the mapping function f. If f returns a negative value, the
character is dropped from the string with no replacement.

---

`PadLeft(s string, padLen int[, padWith any]) -> string`

Returns a string that is padded on the left with the string `padWith` until
the `padLen` length is reached. If padWith is not given, a white space is
used as default padding.

---

`PadRight(s string, padLen int[, padWith any]) -> string`

Returns a string that is padded on the right with the string `padWith` until
the `padLen` length is reached. If padWith is not given, a white space is
used as default padding.

---

`Repeat(s string, count int) -> string`

Returns a new string consisting of count copies of the string s.

- If count is a negative int, it returns empty string.
- If (len(s) * count) overflows, it panics.

---

`Replace(s string, old string, new string[, n int]) -> string`

Returns a copy of the string s with the first n non-overlapping instances
of old replaced by new. If n is not provided or -1, it replaces all
instances.

---

`Split(s string, sep string[, n int]) -> [string]`

Splits s into substrings separated by sep and returns an array of
the substrings between those separators.

n determines the number of substrings to return:

- n < 0: all substrings (default)
- n > 0: at most n substrings; the last substring will be the unsplit remainder.
- n == 0: the result is empty array

---

`SplitAfter(s string, sep string[, n int]) -> [string]`

Slices s into substrings after each instance of sep and returns an array
of those substrings.

n determines the number of substrings to return:

- n < 0: all substrings (default)
- n > 0: at most n substrings; the last substring will be the unsplit remainder.
- n == 0: the result is empty array

---

`Title(s string) -> string`

Deprecated: Returns a copy of the string s with all Unicode letters that
begin words mapped to their Unicode title case.

---

`ToLower(s string) -> string`

Returns s with all Unicode letters mapped to their lower case.

---

`ToTitle(s string) -> string`

Returns a copy of the string s with all Unicode letters mapped to their
Unicode title case.

---

`ToUpper(s string) -> string`

Returns s with all Unicode letters mapped to their upper case.

---

`ToValidUTF8(s string[, replacement string]) -> string`

Returns a copy of the string s with each run of invalid UTF-8 byte
sequences replaced by the replacement string, which may be empty.

---

`Trim(s string, cutset string) -> string`

Returns a slice of the string s with all leading and trailing Unicode
code points contained in cutset removed.

---

`TrimFunc(s string, f func(char) bool) -> string`

Returns a slice of the string s with all leading and trailing Unicode
code points satisfying f removed.

---

`TrimLeft(s string, cutset string) -> string`

Returns a slice of the string s with all leading Unicode code points
contained in cutset removed.

---

`TrimLeftFunc(s string, f func(char) bool) -> string`

Returns a slice of the string s with all leading Unicode code points
c satisfying f(c) removed.

---

`TrimPrefix(s string, prefix string) -> string`

Returns s without the provided leading prefix string. If s doesn't start
with prefix, s is returned unchanged.

---

`TrimRight(s string, cutset string) -> string`

Returns a slice of the string s with all trailing Unicode code points
contained in cutset removed.

---

`TrimRightFunc(s string, f func(char) bool) -> string`

Returns a slice of the string s with all trailing Unicode code points
c satisfying f(c) removed.

---

`TrimSpace(s string) -> string`

Returns a slice of the string s, with all leading and trailing white
space removed, as defined by Unicode.

---

`TrimSuffix(s string, suffix string) -> string`

Returns s without the provided trailing suffix string. If s doesn't end
with suffix, s is returned unchanged.