String functions
Use these functions to work with strings.
Use these functions to work with strings.
strings.Chomp STRING ⟼ anyReturns the given string, removing all trailing newline characters and carriage returns. Read More »
strings.Contains STRING SUBSTRING ⟼ boolReports whether the given string contains the given substring. Read More »
strings.ContainsAny STRING SET ⟼ boolReports whether the given string contains any character within the given set. Read More »
strings.ContainsNonSpace STRING ⟼ boolReports whether the given string contains any non-space characters as defined by Unicode’s White Space property. Read More »
strings.Count SUBSTR STRING ⟼ intReturns the number of non-overlapping instances of the given substring within the given string. Read More »
strings.CountRunes INPUT ⟼ intReturns the number of runes in the given string excluding whitespace. Read More »
strings.CountWords INPUT ⟼ intReturns the number of words in the given string. Read More »
strings.Diff OLDNAME OLD NEWNAME NEW ⟼ stringReturns an anchored diff of the two texts OLD and NEW in the unified diff format. If OLD and NEW are identical, returns an empty string. Read More »
strings.FindRE PATTERN INPUT [LIMIT] ⟼ []stringReturns a slice of strings that match the regular expression. Read More »
strings.FindRESubmatch PATTERN INPUT [LIMIT] ⟼ [][]stringReturns a slice of all successive matches of the regular expression. Each element is a slice of strings holding the text of the leftmost match of the regular expression and the matches, if any, of its subexpressions. Read More »
strings.FirstUpper STRING ⟼ stringReturns the given string, capitalizing the first character. Read More »
strings.HasPrefix STRING PREFIX ⟼ boolReports whether the given string begins with the given prefix. Read More »
strings.HasSuffix STRING SUFFIX ⟼ boolReports whether the given string ends with the given suffix. Read More »
strings.Repeat COUNT INPUT ⟼ stringReturns a new string consisting of zero or more copies of another string. Read More »
strings.Replace INPUT OLD NEW [LIMIT] ⟼ stringReturns a copy of INPUT, replacing all occurrences of OLD with NEW. Read More »
strings.ReplaceRE PATTERN REPLACEMENT INPUT [LIMIT] ⟼ stringReturns a copy of INPUT, replacing all occurrences of a regular expression with a replacement pattern. Read More »
strings.RuneCount INPUT ⟼ intReturns the number of runes in the given string. Read More »
strings.SliceString STRING [START] [END] ⟼ stringReturns a substring of the given string, beginning with the start position and ending before the end position. Read More »
strings.Split STRING DELIM ⟼ stringReturns a slice of strings by splitting the given string by a delimiter. Read More »
strings.Substr STRING [START] [LENGTH] ⟼ stringReturns a substring of the given string, beginning with the start position and ending after the given length. Read More »
strings.Title STRING ⟼ stringReturns the given string, converting it to title case. Read More »
strings.ToLower INPUT ⟼ stringReturns the given string, converting all characters to lowercase. Read More »
strings.ToUpper INPUT ⟼ stringReturns the given string, converting all characters to uppercase. Read More »
strings.Trim INPUT CUTSET ⟼ stringReturns the given string, removing leading and trailing characters specified in the cutset. Read More »
strings.TrimLeft CUTSET STRING ⟼ stringReturns the given string, removing leading characters specified in the cutset. Read More »
strings.TrimPrefix PREFIX STRING ⟼ stringReturns the given string, removing the prefix from the beginning of the string. Read More »
strings.TrimRight CUTSET STRING ⟼ stringReturns the given string, removing trailing characters specified in the cutset. Read More »
strings.TrimSuffix SUFFIX STRING ⟼ stringReturns the given string, removing the suffix from the end of the string. Read More »
strings.Truncate SIZE [ELLIPSIS] INPUT ⟼ template.HTMLReturns the given string, truncating it to a maximum length without cutting words or leaving unclosed HTML tags. Read More »