Namespace: go.std.strings
v1.0Contents
Summary
Provides a low-level interface to the strings package.
Package strings implements simple functions to manipulate UTF-8 encoded strings.
For information about UTF-8 strings in Go, see https://blog.golang.org/strings.
Index
- *Builder
- *Reader
- *Replacer
- Builder
- Clone
- Compare
- Contains
- ContainsAny
- ContainsRune
- Count
- Cut
- EqualFold
- Fields
- HasPrefix
- HasSuffix
- Index
- IndexAny
- IndexByte
- IndexRune
- Join
- LastIndex
- LastIndexAny
- LastIndexByte
- NewReader
- NewReplacer
- Reader
- Repeat
- Replace
- ReplaceAll
- Replacer
- Split
- SplitAfter
- SplitAfterN
- SplitN
- Title
- ToLower
- ToLowerSpecial
- ToTitle
- ToTitleSpecial
- ToUpper
- ToUpperSpecial
- ToValidUTF8
- Trim
- TrimLeft
- TrimPrefix
- TrimRight
- TrimSpace
- TrimSuffix
- arrayOfBuilder
- arrayOfReader
- arrayOfReplacer
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
(None.)
Functions, Macros, and Special Forms
-
Clone
Function v1.0(Clone s)
Clone returns a fresh copy of s.
It guarantees to make a copy of s into a new allocation,
which can be important when retaining only a small substring
of a much larger string. Using Clone can help such programs
use less memory. Of course, since using Clone makes a copy,
overuse of Clone can make programs use more memory.
Clone should typically be used only rarely, and only when
profiling indicates that it is needed.
For strings of length zero the string "" will be returned
and no allocation is made.
Go input arguments: (s string)
Go returns: string
Joker input arguments: [^String s]
Joker returns: ^String -
Compare
Function v1.0(Compare a b)
Compare returns an integer comparing two strings lexicographically.
The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
Compare is included only for symmetry with package bytes.
It is usually clearer and always faster to use the built-in
string comparison operators ==, <, >, and so on.
Go input arguments: (a string, b string)
Go returns: int
Joker input arguments: [^String a, ^String b]
Joker returns: ^Int -
Contains
Function v1.0(Contains s substr)
Contains reports whether substr is within s.
Go input arguments: (s string, substr string)
Go returns: bool
Joker input arguments: [^String s, ^String substr]
Joker returns: ^Boolean -
ContainsAny
Function v1.0(ContainsAny s chars)
ContainsAny reports whether any Unicode code points in chars are within s.
Go input arguments: (s string, chars string)
Go returns: bool
Joker input arguments: [^String s, ^String chars]
Joker returns: ^Boolean -
ContainsRune
Function v1.0(ContainsRune s r)
ContainsRune reports whether the Unicode code point r is within s.
Go input arguments: (s string, r rune)
Go returns: bool
Joker input arguments: [^String s, ^Char r]
Joker returns: ^Boolean -
Count
Function v1.0(Count s substr)
Count counts the number of non-overlapping instances of substr in s.
If substr is an empty string, Count returns 1 + the number of Unicode code points in s.
Go input arguments: (s string, substr string)
Go returns: int
Joker input arguments: [^String s, ^String substr]
Joker returns: ^Int -
Cut
Function v1.0(Cut s sep)
Cut slices s around the first instance of sep,
returning the text before and after sep.
The found result reports whether sep appears in s.
If sep does not appear in s, cut returns s, "", false.
Go input arguments: (s string, sep string)
Go returns: (before string, after string, found bool)
Joker input arguments: [^String s, ^String sep]
Joker returns: [^String before, ^String after, ^Boolean found] -
EqualFold
Function v1.0(EqualFold s t)
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.
Go input arguments: (s string, t string)
Go returns: bool
Joker input arguments: [^String s, ^String t]
Joker returns: ^Boolean -
Fields
Function v1.0(Fields s)
Fields splits the string s around each instance of one or more consecutive white space
characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an
empty slice if s contains only white space.
Go input arguments: (s string)
Go returns: []string
Joker input arguments: [^String s]
Joker returns: ^arrayOfString -
HasPrefix
Function v1.0(HasPrefix s prefix)
HasPrefix tests whether the string s begins with prefix.
Go input arguments: (s string, prefix string)
Go returns: bool
Joker input arguments: [^String s, ^String prefix]
Joker returns: ^Boolean -
HasSuffix
Function v1.0(HasSuffix s suffix)
HasSuffix tests whether the string s ends with suffix.
Go input arguments: (s string, suffix string)
Go returns: bool
Joker input arguments: [^String s, ^String suffix]
Joker returns: ^Boolean -
Index
Function v1.0(Index s substr)
Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.
Go input arguments: (s string, substr string)
Go returns: int
Joker input arguments: [^String s, ^String substr]
Joker returns: ^Int -
IndexAny
Function v1.0(IndexAny s chars)
IndexAny returns the index of the first instance of any Unicode code point
from chars in s, or -1 if no Unicode code point from chars is present in s.
Go input arguments: (s string, chars string)
Go returns: int
Joker input arguments: [^String s, ^String chars]
Joker returns: ^Int -
IndexByte
Function v1.0(IndexByte s c)
IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.
Go input arguments: (s string, c byte)
Go returns: int
Joker input arguments: [^String s, ^Byte c]
Joker returns: ^Int -
IndexRune
Function v1.0(IndexRune s r)
IndexRune returns the index of the first instance of the Unicode code point
r, or -1 if rune is not present in s.
If r is utf8.RuneError, it returns the first instance of any
invalid UTF-8 byte sequence.
Go input arguments: (s string, r rune)
Go returns: int
Joker input arguments: [^String s, ^Char r]
Joker returns: ^Int -
Join
Function v1.0(Join elems sep)
Join concatenates the elements of its first argument to create a single string. The separator
string sep is placed between elements in the resulting string.
Go input arguments: (elems []string, sep string)
Go returns: string
Joker input arguments: [^arrayOfString elems, ^String sep]
Joker returns: ^String -
LastIndex
Function v1.0(LastIndex s substr)
LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.
Go input arguments: (s string, substr string)
Go returns: int
Joker input arguments: [^String s, ^String substr]
Joker returns: ^Int -
LastIndexAny
Function v1.0(LastIndexAny s chars)
LastIndexAny returns the index of the last instance of any Unicode code
point from chars in s, or -1 if no Unicode code point from chars is
present in s.
Go input arguments: (s string, chars string)
Go returns: int
Joker input arguments: [^String s, ^String chars]
Joker returns: ^Int -
LastIndexByte
Function v1.0(LastIndexByte s c)
LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.
Go input arguments: (s string, c byte)
Go returns: int
Joker input arguments: [^String s, ^Byte c]
Joker returns: ^Int -
NewReader
Function v1.0(NewReader s)
NewReader returns a new Reader reading from s.
It is similar to bytes.NewBufferString but more efficient and read-only.
Go input arguments: (s string)
Go returns: *Reader
Joker input arguments: [^String s]
Joker returns: ^*Reader -
NewReplacer
Function v1.0(NewReplacer & oldnew)
NewReplacer returns a new Replacer from a list of old, new string
pairs. Replacements are performed in the order they appear in the
target string, without overlapping matches. The old string
comparisons are done in argument order.
NewReplacer panics if given an odd number of arguments.
Go input arguments: (oldnew ...string)
Go returns: *Replacer
Joker input arguments: [& ^String oldnew]
Joker returns: ^*Replacer -
Repeat
Function v1.0(Repeat s count)
Repeat returns a new string consisting of count copies of the string s.
It panics if count is negative or if
the result of (len(s) * count) overflows.
Go input arguments: (s string, count int)
Go returns: string
Joker input arguments: [^String s, ^Int count]
Joker returns: ^String -
Replace
Function v1.0(Replace s old new n)
Replace returns a copy of the string s with the first n
non-overlapping instances of old replaced by new.
If old is empty, it matches at the beginning of the string
and after each UTF-8 sequence, yielding up to k+1 replacements
for a k-rune string.
If n < 0, there is no limit on the number of replacements.
Go input arguments: (s string, old string, new string, n int)
Go returns: string
Joker input arguments: [^String s, ^String old, ^String new, ^Int n]
Joker returns: ^String -
ReplaceAll
Function v1.0(ReplaceAll s old new)
ReplaceAll returns a copy of the string s with all
non-overlapping instances of old replaced by new.
If old is empty, it matches at the beginning of the string
and after each UTF-8 sequence, yielding up to k+1 replacements
for a k-rune string.
Go input arguments: (s string, old string, new string)
Go returns: string
Joker input arguments: [^String s, ^String old, ^String new]
Joker returns: ^String -
Split
Function v1.0(Split s sep)
Split slices s into all substrings separated by sep and returns a slice of
the substrings between those separators.
If s does not contain sep and sep is not empty, Split returns a
slice of length 1 whose only element is s.
If sep is empty, Split splits after each UTF-8 sequence. If both s
and sep are empty, Split returns an empty slice.
It is equivalent to SplitN with a count of -1.
To split around the first instance of a separator, see Cut.
Go input arguments: (s string, sep string)
Go returns: []string
Joker input arguments: [^String s, ^String sep]
Joker returns: ^arrayOfString -
SplitAfter
Function v1.0(SplitAfter s sep)
SplitAfter slices s into all substrings after each instance of sep and
returns a slice of those substrings.
If s does not contain sep and sep is not empty, SplitAfter returns
a slice of length 1 whose only element is s.
If sep is empty, SplitAfter splits after each UTF-8 sequence. If
both s and sep are empty, SplitAfter returns an empty slice.
It is equivalent to SplitAfterN with a count of -1.
Go input arguments: (s string, sep string)
Go returns: []string
Joker input arguments: [^String s, ^String sep]
Joker returns: ^arrayOfString -
SplitAfterN
Function v1.0(SplitAfterN s sep n)
SplitAfterN slices s into substrings after each instance of sep and
returns a slice of those substrings.
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder.
n == 0: the result is nil (zero substrings)
n < 0: all substrings
Edge cases for s and sep (for example, empty strings) are handled
as described in the documentation for SplitAfter.
Go input arguments: (s string, sep string, n int)
Go returns: []string
Joker input arguments: [^String s, ^String sep, ^Int n]
Joker returns: ^arrayOfString -
SplitN
Function v1.0(SplitN s sep n)
SplitN slices s into substrings separated by sep and returns a slice of
the substrings between those separators.
The count determines the number of substrings to return:
n > 0: at most n substrings; the last substring will be the unsplit remainder.
n == 0: the result is nil (zero substrings)
n < 0: all substrings
Edge cases for s and sep (for example, empty strings) are handled
as described in the documentation for Split.
To split around the first instance of a separator, see Cut.
Go input arguments: (s string, sep string, n int)
Go returns: []string
Joker input arguments: [^String s, ^String sep, ^Int n]
Joker returns: ^arrayOfString -
Title
Function v1.0(Title s)
Title returns a copy of the string s with all Unicode letters that begin words
mapped to their Unicode title case.
Deprecated: The rule Title uses for word boundaries does not handle Unicode
punctuation properly. Use golang.org/x/text/cases instead.
Go input arguments: (s string)
Go returns: string
Joker input arguments: [^String s]
Joker returns: ^String -
ToLower
Function v1.0(ToLower s)
ToLower returns s with all Unicode letters mapped to their lower case.
Go input arguments: (s string)
Go returns: string
Joker input arguments: [^String s]
Joker returns: ^String -
ToLowerSpecial
Function v1.0(ToLowerSpecial c s)
ToLowerSpecial returns a copy of the string s with all Unicode letters mapped to their
lower case using the case mapping specified by c.
Go input arguments: (c unicode.SpecialCase, s string)
Go returns: string
Joker input arguments: [^go.std.unicode/SpecialCase c, ^String s]
Joker returns: ^String -
ToTitle
Function v1.0(ToTitle s)
ToTitle returns a copy of the string s with all Unicode letters mapped to
their Unicode title case.
Go input arguments: (s string)
Go returns: string
Joker input arguments: [^String s]
Joker returns: ^String -
ToTitleSpecial
Function v1.0(ToTitleSpecial c s)
ToTitleSpecial returns a copy of the string s with all Unicode letters mapped to their
Unicode title case, giving priority to the special casing rules.
Go input arguments: (c unicode.SpecialCase, s string)
Go returns: string
Joker input arguments: [^go.std.unicode/SpecialCase c, ^String s]
Joker returns: ^String -
ToUpper
Function v1.0(ToUpper s)
ToUpper returns s with all Unicode letters mapped to their upper case.
Go input arguments: (s string)
Go returns: string
Joker input arguments: [^String s]
Joker returns: ^String -
ToUpperSpecial
Function v1.0(ToUpperSpecial c s)
ToUpperSpecial returns a copy of the string s with all Unicode letters mapped to their
upper case using the case mapping specified by c.
Go input arguments: (c unicode.SpecialCase, s string)
Go returns: string
Joker input arguments: [^go.std.unicode/SpecialCase c, ^String s]
Joker returns: ^String -
ToValidUTF8
Function v1.0(ToValidUTF8 s replacement)
ToValidUTF8 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.
Go input arguments: (s string, replacement string)
Go returns: string
Joker input arguments: [^String s, ^String replacement]
Joker returns: ^String -
Trim
Function v1.0(Trim s cutset)
Trim returns a slice of the string s with all leading and
trailing Unicode code points contained in cutset removed.
Go input arguments: (s string, cutset string)
Go returns: string
Joker input arguments: [^String s, ^String cutset]
Joker returns: ^String -
TrimLeft
Function v1.0(TrimLeft s cutset)
TrimLeft returns a slice of the string s with all leading
Unicode code points contained in cutset removed.
To remove a prefix, use TrimPrefix instead.
Go input arguments: (s string, cutset string)
Go returns: string
Joker input arguments: [^String s, ^String cutset]
Joker returns: ^String -
TrimPrefix
Function v1.0(TrimPrefix s prefix)
TrimPrefix returns s without the provided leading prefix string.
If s doesn't start with prefix, s is returned unchanged.
Go input arguments: (s string, prefix string)
Go returns: string
Joker input arguments: [^String s, ^String prefix]
Joker returns: ^String -
TrimRight
Function v1.0(TrimRight s cutset)
TrimRight returns a slice of the string s, with all trailing
Unicode code points contained in cutset removed.
To remove a suffix, use TrimSuffix instead.
Go input arguments: (s string, cutset string)
Go returns: string
Joker input arguments: [^String s, ^String cutset]
Joker returns: ^String -
TrimSpace
Function v1.0(TrimSpace s)
TrimSpace returns a slice of the string s, with all leading
and trailing white space removed, as defined by Unicode.
Go input arguments: (s string)
Go returns: string
Joker input arguments: [^String s]
Joker returns: ^String -
TrimSuffix
Function v1.0(TrimSuffix s suffix)
TrimSuffix returns s without the provided trailing suffix string.
If s doesn't end with suffix, s is returned unchanged.
Go input arguments: (s string, suffix string)
Go returns: string
Joker input arguments: [^String s, ^String suffix]
Joker returns: ^String
Types
-
*Builder
Concrete Type v1.0A Builder is used to efficiently build a string using Write methods.
It minimizes memory copying. The zero value is ready to use.
Do not copy a non-zero Builder.
-
Cap
Receiver for *Builder v1.0([])
Cap returns the capacity of the builder's underlying byte slice. It is the
total space allocated for the string being built and includes any bytes
already written.
-
Grow
Receiver for *Builder v1.0([n])
Grow grows b's capacity, if necessary, to guarantee space for
another n bytes. After Grow(n), at least n bytes can be written to b
without another allocation. If n is negative, Grow panics.
-
Len
Receiver for *Builder v1.0([])
Len returns the number of accumulated bytes; b.Len() == len(b.String()).
-
Reset
Receiver for *Builder v1.0([])
Reset resets the Builder to be empty.
-
String
Receiver for *Builder v1.0([])
String returns the accumulated string.
-
Write
Receiver for *Builder v1.0([p])
Write appends the contents of p to b's buffer.
Write always returns len(p), nil.
-
WriteByte
Receiver for *Builder v1.0([c])
WriteByte appends the byte c to b's buffer.
The returned error is always nil.
-
WriteRune
Receiver for *Builder v1.0([r])
WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer.
It returns the length of r and a nil error.
-
WriteString
Receiver for *Builder v1.0([s])
WriteString appends the contents of s to b's buffer.
It returns the length of s and a nil error.
-
*Reader
Concrete Type v1.0A Reader implements the io.Reader, io.ReaderAt, io.ByteReader, io.ByteScanner,
io.RuneReader, io.RuneScanner, io.Seeker, and io.WriterTo interfaces by reading
from a string.
The zero value for Reader operates like a Reader of an empty string.
-
Len
Receiver for *Reader v1.0([])
Len returns the number of bytes of the unread portion of the
string.
-
Read
Receiver for *Reader v1.0([b])
Read implements the io.Reader interface.
-
ReadAt
Receiver for *Reader v1.0([b off])
ReadAt implements the io.ReaderAt interface.
-
ReadByte
Receiver for *Reader v1.0([])
ReadByte implements the io.ByteReader interface.
-
ReadRune
Receiver for *Reader v1.0([])
ReadRune implements the io.RuneReader interface.
-
Reset
Receiver for *Reader v1.0([s])
Reset resets the Reader to be reading from s.
-
Seek
Receiver for *Reader v1.0([offset whence])
Seek implements the io.Seeker interface.
-
Size
Receiver for *Reader v1.0([])
Size returns the original length of the underlying string.
Size is the number of bytes available for reading via ReadAt.
The returned value is always the same and is not affected by calls
to any other method.
-
UnreadByte
Receiver for *Reader v1.0([])
UnreadByte implements the io.ByteScanner interface.
-
UnreadRune
Receiver for *Reader v1.0([])
UnreadRune implements the io.RuneScanner interface.
-
WriteTo
Receiver for *Reader v1.0([w])
WriteTo implements the io.WriterTo interface.
-
*Replacer
Concrete Type v1.0Replacer replaces a list of strings with replacements.
It is safe for concurrent use by multiple goroutines.
-
Replace
Receiver for *Replacer v1.0([s])
Replace returns a copy of s with all replacements performed.
-
WriteString
Receiver for *Replacer v1.0([w s])
WriteString writes s to w with all replacements performed.
-
Builder
Concrete Type v1.0A Builder is used to efficiently build a string using Write methods.
It minimizes memory copying. The zero value is ready to use.
Do not copy a non-zero Builder.
-
Reader
Concrete Type v1.0A Reader implements the io.Reader, io.ReaderAt, io.ByteReader, io.ByteScanner,
io.RuneReader, io.RuneScanner, io.Seeker, and io.WriterTo interfaces by reading
from a string.
The zero value for Reader operates like a Reader of an empty string.
-
Replacer
Concrete Type v1.0Replacer replaces a list of strings with replacements.
It is safe for concurrent use by multiple goroutines.
-
arrayOfBuilder
Concrete Type v1.0A Builder is used to efficiently build a string using Write methods.
It minimizes memory copying. The zero value is ready to use.
Do not copy a non-zero Builder.
-
arrayOfReader
Concrete Type v1.0A Reader implements the io.Reader, io.ReaderAt, io.ByteReader, io.ByteScanner,
io.RuneReader, io.RuneScanner, io.Seeker, and io.WriterTo interfaces by reading
from a string.
The zero value for Reader operates like a Reader of an empty string.
-
arrayOfReplacer
Concrete Type v1.0Replacer replaces a list of strings with replacements.
It is safe for concurrent use by multiple goroutines.