Documentation
¶
Index ¶
- type String
- func (s String) After(sep string) String
- func (s String) AfterLast(sep string) String
- func (s String) Append(parts ...string) String
- func (s String) Before(sep string) String
- func (s String) BeforeLast(sep string) String
- func (s String) Between(start, end string) String
- func (s String) BetweenFirst(start, end string) String
- func (s String) Camel() String
- func (s String) CharAt(idx int) (rune, bool)
- func (s String) ChopEnd(suffixes ...string) String
- func (s String) ChopStart(prefixes ...string) String
- func (s String) Contains(subs ...string) bool
- func (s String) ContainsAll(subs ...string) bool
- func (s String) ContainsAllFold(subs ...string) bool
- func (s String) ContainsFold(subs ...string) bool
- func (s String) Count(sub string) int
- func (s String) Deduplicate(char rune) String
- func (s String) DoesntContain(subs ...string) bool
- func (s String) DoesntContainFold(subs ...string) bool
- func (s String) DoesntEndWith(suffixes ...string) bool
- func (s String) DoesntEndWithFold(suffixes ...string) bool
- func (s String) DoesntStartWith(prefixes ...string) bool
- func (s String) DoesntStartWithFold(prefixes ...string) bool
- func (s String) EndsWith(suffixes ...string) bool
- func (s String) EndsWithFold(suffixes ...string) bool
- func (s String) EnsurePrefix(prefix string) String
- func (s String) EnsureSuffix(suffix string) String
- func (s String) Equals(other string) bool
- func (s String) EqualsFold(other string) bool
- func (s String) Excerpt(needle string, radius int, omission string) String
- func (s String) FirstWord() String
- func (s String) FromBase64() (String, error)
- func (s String) GoString() string
- func (s String) Headline() String
- func (s String) Index(sub string) int
- func (s String) Is(patterns ...string) bool
- func (s String) IsASCII() bool
- func (s String) IsBlank() bool
- func (s String) IsEmpty() bool
- func (s String) IsMatch(re *regexp.Regexp) bool
- func (s String) Join(words []string, sep string) String
- func (s String) Kebab() String
- func (s String) LastIndex(sub string) int
- func (s String) LastWord() String
- func (s String) LcFirst() String
- func (s String) Len() int
- func (s String) Limit(length int, suffix string) String
- func (s String) Mask(mask rune, revealLeft, revealRight int) String
- func (s String) NewLine() String
- func (s String) PadBoth(length int, pad string) String
- func (s String) PadLeft(length int, pad string) String
- func (s String) PadRight(length int, pad string) String
- func (s String) Pascal() String
- func (s String) Prepend(parts ...string) String
- func (s String) Remove(subs ...string) String
- func (s String) Repeat(count int) String
- func (s String) ReplaceArray(olds []string, repl string) String
- func (s String) ReplaceFirst(old, repl string) String
- func (s String) ReplaceLast(old, repl string) String
- func (s String) ReplaceMatches(pattern *regexp.Regexp, repl func(string) string) String
- func (s String) Reverse() String
- func (s String) RuneCount() int
- func (s String) Slice(start, end int) String
- func (s String) Slug(sep string) String
- func (s String) Snake(sep string) String
- func (s String) Split(sep string) []string
- func (s String) SplitWords() []string
- func (s String) Squish() String
- func (s String) StartsWith(prefixes ...string) bool
- func (s String) StartsWithFold(prefixes ...string) bool
- func (s String) String() string
- func (s String) Swap(pairs map[string]string) String
- func (s String) Take(length int) String
- func (s String) TakeLast(length int) String
- func (s String) Title() String
- func (s String) ToBase64() String
- func (s String) ToLower() String
- func (s String) ToTitle() String
- func (s String) ToUpper() String
- func (s String) Trim(cutset string) String
- func (s String) TrimLeft(cutset string) String
- func (s String) TrimRight(cutset string) String
- func (s String) UcFirst() String
- func (s String) UcSplit() []string
- func (s String) UcWords() String
- func (s String) Unwrap(before, after string) String
- func (s String) WordCount() int
- func (s String) Words(count int, suffix string) String
- func (s String) Wrap(before, after string) String
- func (s String) WrapWords(width int, breakStr string) String
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type String ¶
type String struct {
// contains filtered or unexported fields
}
String is an immutable wrapper for fluent string operations. @group Fluent
func Of ¶
Of wraps a raw string with fluent helpers. @group Fluent
Example: wrap raw string
v := str.Of("gopher")
godump.Dump(v.String())
// #string gopher
func (String) After ¶
After returns the substring after the first occurrence of sep. If sep is empty or not found, the original string is returned. @group Substrings
Example: slice after marker
v := str.Of("gopher::go").After("::").String()
godump.Dump(v)
// #string go
func (String) AfterLast ¶
AfterLast returns the substring after the last occurrence of sep. If sep is empty or not found, the original string is returned. @group Substrings
Example: slice after last separator
v := str.Of("pkg/path/file.txt").AfterLast("/").String()
godump.Dump(v)
// #string file.txt
func (String) Append ¶
Append concatenates the provided parts to the end of the string. @group Compose
Example: append text
v := str.Of("Go").Append("Forj", "!").String()
godump.Dump(v)
// #string GoForj!
func (String) Before ¶
Before returns the substring before the first occurrence of sep. If sep is empty or not found, the original string is returned. @group Substrings
Example: slice before marker
v := str.Of("gopher::go").Before("::").String()
godump.Dump(v)
// #string gopher
func (String) BeforeLast ¶
BeforeLast returns the substring before the last occurrence of sep. If sep is empty or not found, the original string is returned. @group Substrings
Example: slice before last separator
v := str.Of("pkg/path/file.txt").BeforeLast("/").String()
godump.Dump(v)
// #string pkg/path
func (String) Between ¶
Between returns the substring between the first occurrence of start and the last occurrence of end. Returns an empty string if either marker is missing or overlapping. @group Substrings
Example: between first and last
v := str.Of("This is my name").Between("This", "name").String()
godump.Dump(v)
// #string is my
func (String) BetweenFirst ¶
BetweenFirst returns the substring between the first occurrence of start and the first occurrence of end after it. Returns an empty string if markers are missing. @group Substrings
Example: minimal span between markers
v := str.Of("[a] bc [d]").BetweenFirst("[", "]").String()
godump.Dump(v)
// #string a
func (String) Camel ¶
Camel converts the string to camelCase. @group Case
Example: camel case
v := str.Of("foo_bar baz").Camel().String()
godump.Dump(v)
// #string fooBarBaz
func (String) CharAt ¶
CharAt returns the rune at the given index and true if within bounds. @group Substrings
Example: rune lookup
v, ok := str.Of("gopher").CharAt(2)
godump.Dump(string(v), ok)
// #string p
// #bool true
func (String) ChopEnd ¶
ChopEnd removes the first matching suffix if present. @group Affixes
Example: chop end
v := str.Of("file.txt").ChopEnd(".txt", ".md").String()
godump.Dump(v)
// #string file
func (String) ChopStart ¶
ChopStart removes the first matching prefix if present. @group Affixes
Example: chop start
v := str.Of("https://goforj.dev").ChopStart("https://", "http://").String()
godump.Dump(v)
// #string goforj.dev
func (String) Contains ¶
Contains reports whether the string contains any of the provided substrings (case-sensitive). Empty substrings return true to match strings.Contains semantics. @group Search
Example: contains any
v := str.Of("Go means gophers").Contains("rust", "gopher")
godump.Dump(v)
// #bool true
func (String) ContainsAll ¶
ContainsAll reports whether the string contains all provided substrings (case-sensitive). Empty substrings are ignored. @group Search
Example: contains all
v := str.Of("Go means gophers").ContainsAll("Go", "gopher")
godump.Dump(v)
// #bool true
func (String) ContainsAllFold ¶
ContainsAllFold reports whether the string contains all provided substrings, using Unicode case folding for comparisons. Empty substrings are ignored. @group Search
Example: contains all (case-insensitive)
v := str.Of("Go means gophers").ContainsAllFold("go", "GOPHER")
godump.Dump(v)
// #bool true
func (String) ContainsFold ¶
ContainsFold reports whether the string contains any of the provided substrings, using Unicode case folding for comparisons. Empty substrings return true. @group Search
Example: contains any (case-insensitive)
v := str.Of("Go means gophers").ContainsFold("GOPHER", "rust")
godump.Dump(v)
// #bool true
func (String) Count ¶
Count returns the number of non-overlapping occurrences of sub. @group Search
Example: count substring
v := str.Of("gogophergo").Count("go")
godump.Dump(v)
// #int 3
func (String) Deduplicate ¶
Deduplicate collapses consecutive instances of char into a single instance. If char is zero, space is used. @group Cleanup
Example: collapse spaces
v := str.Of("The Go Playground").Deduplicate(' ').String()
godump.Dump(v)
// #string The Go Playground
func (String) DoesntContain ¶
DoesntContain reports true if none of the substrings are found (case-sensitive). Empty substrings are ignored. @group Search
Example: doesn't contain any
v := str.Of("gophers are great")
godump.Dump(v.DoesntContain("rust", "beam"))
// #bool true
func (String) DoesntContainFold ¶
DoesntContainFold reports true if none of the substrings are found using Unicode case folding. Empty substrings are ignored. @group Search
Example: doesn't contain (case-insensitive)
v := str.Of("gophers are great")
godump.Dump(v.DoesntContainFold("GOPHER"))
// #bool false
func (String) DoesntEndWith ¶
DoesntEndWith reports true if the string ends with none of the provided suffixes (case-sensitive). @group Search
Example: doesn't end with any
v := str.Of("gopher")
godump.Dump(v.DoesntEndWith("her", "cat"))
// #bool false
func (String) DoesntEndWithFold ¶
DoesntEndWithFold reports true if the string ends with none of the provided suffixes using Unicode case folding. @group Search
Example: doesn't end with (case-insensitive)
v := str.Of("gopher")
godump.Dump(v.DoesntEndWithFold("HER"))
// #bool false
func (String) DoesntStartWith ¶
DoesntStartWith reports true if the string starts with none of the provided prefixes (case-sensitive). @group Search
Example: doesn't start with any
v := str.Of("gopher")
godump.Dump(v.DoesntStartWith("go", "rust"))
// #bool false
func (String) DoesntStartWithFold ¶
DoesntStartWithFold reports true if the string starts with none of the provided prefixes using Unicode case folding. @group Search
Example: doesn't start with (case-insensitive)
v := str.Of("gopher")
godump.Dump(v.DoesntStartWithFold("GO"))
// #bool false
func (String) EndsWith ¶
EndsWith reports whether the string ends with any of the provided suffixes (case-sensitive). @group Search
Example: ends with any
v := str.Of("gopher").EndsWith("her", "cat")
godump.Dump(v)
// #bool true
func (String) EndsWithFold ¶
EndsWithFold reports whether the string ends with any of the provided suffixes using Unicode case folding. @group Search
Example: ends with (case-insensitive)
v := str.Of("gopher").EndsWithFold("HER")
godump.Dump(v)
// #bool true
func (String) EnsurePrefix ¶
EnsurePrefix ensures the string starts with prefix, adding it if missing. @group Affixes
Example: ensure prefix
v := str.Of("path/to").EnsurePrefix("/").String()
godump.Dump(v)
// #string /path/to
func (String) EnsureSuffix ¶
EnsureSuffix ensures the string ends with suffix, adding it if missing. @group Affixes
Example: ensure suffix
v := str.Of("path/to").EnsureSuffix("/").String()
godump.Dump(v)
// #string path/to/
func (String) Equals ¶
Equals reports whether the string exactly matches other (case-sensitive). @group Comparison
Example: exact match
v := str.Of("gopher").Equals("gopher")
godump.Dump(v)
// #bool true
func (String) EqualsFold ¶
EqualsFold reports whether the string matches other using Unicode case folding. @group Comparison
Example: case-insensitive match
v := str.Of("gopher").EqualsFold("GOPHER")
godump.Dump(v)
// #bool true
func (String) Excerpt ¶
Excerpt returns a snippet around the first occurrence of needle with the given radius. If needle is not found, an empty string is returned. If radius <= 0, a default of 100 is used. Omission is used at the start/end when text is trimmed (default "..."). @group Snippet
Example: excerpt with radius
v := str.Of("This is my name").Excerpt("my", 3, "...")
godump.Dump(v.String())
// #string ...is my na...
func (String) FirstWord ¶
FirstWord returns the first word token or empty string. @group Words
Example: first word
v := str.Of("Hello world")
godump.Dump(v.FirstWord().String())
// #string Hello
func (String) FromBase64 ¶
FromBase64 decodes a standard Base64 string. @group Encoding
Example: base64 decode
v, err := str.Of("Z29waGVy").FromBase64()
godump.Dump(v.String(), err)
// #string gopher
// #error <nil>
func (String) GoString ¶
GoString allows %#v formatting to print the raw string. @group Fluent
Example: fmt %#v uses GoString
v := str.Of("go")
godump.Dump(fmt.Sprintf("%#v", v))
// #string go
func (String) Headline ¶
Headline converts the string into a human-friendly headline: splits on case/underscores/dashes/whitespace, title-cases words, and lowercases small words (except the first). @group Case
Example: headline
v := str.Of("emailNotification_sent").Headline().String()
godump.Dump(v)
// #string Email Notification Sent
func (String) Index ¶
Index returns the rune index of the first occurrence of sub, or -1 if not found. @group Search
Example: first rune index
v := str.Of("héllo").Index("llo")
godump.Dump(v)
// #int 2
func (String) Is ¶
Is reports whether the string matches any of the provided wildcard patterns. Patterns use '*' as a wildcard. Case-sensitive. @group Match
Example: wildcard match
v := str.Of("foo/bar").Is("foo/*")
godump.Dump(v)
// #bool true
func (String) IsASCII ¶
IsASCII reports whether the string consists solely of 7-bit ASCII runes. @group Checks
Example: ASCII check
v := str.Of("gopher").IsASCII()
godump.Dump(v)
// #bool true
func (String) IsBlank ¶
IsBlank reports whether the string contains only Unicode whitespace. @group Checks
Example: blank check
v := str.Of(" \\t\\n")
godump.Dump(v.IsBlank())
// #bool true
func (String) IsEmpty ¶
IsEmpty reports whether the string has zero length. @group Checks
Example: empty check
v := str.Of("").IsEmpty()
godump.Dump(v)
// #bool true
func (String) IsMatch ¶
IsMatch reports whether the string matches the provided regular expression. @group Match
Example: regex match
v := str.Of("abc123").IsMatch(regexp.MustCompile(`\d+`))
godump.Dump(v)
// #bool true
func (String) Join ¶
Join joins the provided words with sep. @group Words
Example: join words
v := str.Of("unused").Join([]string{"foo", "bar"}, "-").String()
godump.Dump(v)
// #string foo-bar
func (String) Kebab ¶
Kebab converts the string to kebab-case. @group Case
Example: kebab case
v := str.Of("fooBar baz").Kebab().String()
godump.Dump(v)
// #string foo-bar-baz
func (String) LastIndex ¶
LastIndex returns the rune index of the last occurrence of sub, or -1 if not found. @group Search
Example: last rune index
v := str.Of("go gophers go").LastIndex("go")
godump.Dump(v)
// #int 10
func (String) LastWord ¶
LastWord returns the last word token or empty string. @group Words
Example: last word
v := str.Of("Hello world").LastWord().String()
godump.Dump(v)
// #string world
func (String) LcFirst ¶
LcFirst returns the string with the first rune lower-cased. @group Case
Example: lowercase first rune
v := str.Of("Gopher")
godump.Dump(v)
// #string gopher
func (String) Len ¶
Len returns the number of runes in the string. @group Length
Example: count runes instead of bytes
v := str.Of("gophers 🦫").Len()
godump.Dump(v)
// #int 9
func (String) Limit ¶
Limit truncates the string to length runes, appending suffix if truncation occurs. @group Substrings
Example: limit with suffix
v := str.Of("Perfectly balanced, as all things should be.").Limit(10, "...").String()
godump.Dump(v)
// #string Perfectly...
func (String) Mask ¶
Mask replaces the middle of the string with the given rune, revealing revealLeft runes at the start and revealRight runes at the end. Negative reveal values count from the end. If the reveal counts cover the whole string, the original string is returned. @group Masking
Example: mask email
v := str.Of("gopher@example.com").Mask('*', 3, 4).String()
godump.Dump(v)
// #string gop***********.com
func (String) NewLine ¶
NewLine appends a newline character to the string. @group Compose
Example: append newline
v := str.Of("hello").NewLine().Append("world").String()
godump.Dump(v)
// #string hello\nworld
func (String) PadBoth ¶
PadBoth pads the string on both sides to reach length runes using pad (defaults to space). @group Padding
Example: pad both
v := str.Of("go").PadBoth(6, "-").String()
godump.Dump(v)
// #string --go--
func (String) PadLeft ¶
PadLeft pads the string on the left to reach length runes using pad (defaults to space). @group Padding
Example: pad left
v := str.Of("go").PadLeft(5, " ").String()
godump.Dump(v)
// #string \u00a0\u00a0\u00a0go
func (String) PadRight ¶
PadRight pads the string on the right to reach length runes using pad (defaults to space). @group Padding
Example: pad right
v := str.Of("go").PadRight(5, ".").String()
godump.Dump(v)
// #string go...
func (String) Pascal ¶
Pascal converts the string to PascalCase. @group Case
Example: pascal case
v := str.Of("foo_bar baz")
godump.Dump(v)
// #string FooBarBaz
func (String) Prepend ¶
Prepend concatenates the provided parts to the beginning of the string. @group Compose
Example: prepend text
v := str.Of("World").Prepend("Hello ", "Go ").String()
godump.Dump(v)
// #string Hello Go World
func (String) Remove ¶
Remove deletes all occurrences of provided substrings. @group Replace
Example: remove substrings
v := str.Of("The Go Toolkit").Remove("Go ").String()
godump.Dump(v)
// #string The Toolkit
func (String) Repeat ¶
Repeat repeats the string count times (non-negative). @group Transform
Example: repeat string
v := str.Of("go").Repeat(3).String()
godump.Dump(v)
// #string gogogo
func (String) ReplaceArray ¶
ReplaceArray replaces all occurrences of each old in olds with repl. @group Replace
Example: replace many
v := str.Of("The---Go---Toolkit")
godump.Dump(v.ReplaceArray([]string{"---"}, "-").String())
// #string The-Go-Toolkit
func (String) ReplaceFirst ¶
ReplaceFirst replaces the first occurrence of old with repl. @group Replace
Example: replace first
v := str.Of("gopher gopher").ReplaceFirst("gopher", "go").String()
godump.Dump(v)
// #string go gopher
func (String) ReplaceLast ¶
ReplaceLast replaces the last occurrence of old with repl. @group Replace
Example: replace last
v := str.Of("gopher gopher").ReplaceLast("gopher", "go").String()
godump.Dump(v)
// #string gopher go
func (String) ReplaceMatches ¶
ReplaceMatches applies repl to each regex match and returns the result. @group Replace
Example: regex replace with callback
re := regexp.MustCompile(`\d+`)
v := str.Of("Hello 123 World").ReplaceMatches(re, func(m string) string { return "[" + m + "]" }).String()
godump.Dump(v)
// #string Hello [123] World
func (String) Reverse ¶
Reverse returns a rune-safe reversed string. @group Transform
Example: reverse
v := str.Of("naïve").Reverse().String()
godump.Dump(v)
// #string evïan
func (String) RuneCount ¶
RuneCount is an alias for Len to make intent explicit in mixed codebases. @group Length
Example: alias for Len
v := str.Of("naïve").RuneCount()
godump.Dump(v)
// #int 5
func (String) Slice ¶
Slice returns the substring between rune offsets [start:end). Indices are clamped; if start >= end the result is empty. @group Substrings
Example: rune-safe slice
v := str.Of("naïve café").Slice(3, 7).String()
godump.Dump(v)
// #string e ca
func (String) Slug ¶
Slug produces an ASCII slug using the provided separator (default "-"), stripping accents where possible. Not locale-aware; intended for identifiers/URLs. @group Slug
Example: build slug
v := str.Of("Go Forj Toolkit").Slug("-").String()
godump.Dump(v)
// #string go-forj-toolkit
func (String) Snake ¶
Snake converts the string to snake_case using the provided separator (default "_"). @group Case
Example: snake case
v := str.Of("fooBar baz").Snake("_").String()
godump.Dump(v)
// #string foo_bar_baz
func (String) Split ¶
Split splits the string by the given separator. @group Split
Example: split on comma
v := str.Of("a,b,c").Split(",")
godump.Dump(v)
// #[]string [a b c]
func (String) SplitWords ¶
SplitWords splits the string into words (Unicode letters/digits runs). @group Words
Example: split words
v := str.Of("one, two, three").SplitWords()
godump.Dump(v)
// #[]string [one two three]
func (String) Squish ¶
Squish trims leading/trailing whitespace and collapses internal whitespace to single spaces. @group Cleanup
Example: squish whitespace
v := str.Of(" go forj ").Squish().String()
godump.Dump(v)
// #string go forj
func (String) StartsWith ¶
StartsWith reports whether the string starts with any of the provided prefixes (case-sensitive). @group Search
Example: starts with any
v := str.Of("gopher").StartsWith("go", "rust")
godump.Dump(v)
// #bool true
func (String) StartsWithFold ¶
StartsWithFold reports whether the string starts with any of the provided prefixes using Unicode case folding. @group Search
Example: starts with (case-insensitive)
v := str.Of("gopher").StartsWithFold("GO")
godump.Dump(v)
// #bool true
func (String) String ¶
String returns the underlying raw string value. @group Fluent
Example: unwrap to plain string
v := str.Of("go").String()
godump.Dump(v)
// #string go
func (String) Swap ¶
Swap replaces multiple values using strings.Replacer built from a map. @group Replace
Example: swap map
pairs := map[string]string{"Gophers": "GoForj", "are": "is", "great": "fantastic"}
v := str.Of("Gophers are great!").Swap(pairs).String()
godump.Dump(v)
// #string GoForj is fantastic!
func (String) Take ¶
Take returns the first length runes of the string (clamped). @group Substrings
Example: take head
v := str.Of("gophers").Take(3).String()
godump.Dump(v)
// #string gop
func (String) TakeLast ¶
TakeLast returns the last length runes of the string (clamped). @group Substrings
Example: take tail
v := str.Of("gophers").TakeLast(4).String()
godump.Dump(v)
// #string hers
func (String) Title ¶
Title converts the string to title case (first letter of each word upper, rest lower) using Unicode rules. @group Case
Example: title case words
v := str.Of("a nice title uses the correct case").Title().String()
godump.Dump(v)
// #string A Nice Title Uses The Correct Case
func (String) ToBase64 ¶
ToBase64 encodes the string using standard Base64. @group Encoding
Example: base64 encode
v := str.Of("gopher").ToBase64().String()
godump.Dump(v)
// #string Z29waGVy
func (String) ToLower ¶
ToLower returns a lowercase copy of the string using Unicode rules. @group Case
Example: lowercase text
v := str.Of("GoLang").ToLower().String()
godump.Dump(v)
// #string golang
func (String) ToTitle ¶
ToTitle returns a title-cased copy where all letters are mapped using Unicode title case. @group Case
Example: title map runes
v := str.Of("ß").ToTitle().String()
godump.Dump(v)
// #string SS
func (String) ToUpper ¶
ToUpper returns an uppercase copy of the string using Unicode rules. @group Case
Example: uppercase text
v := str.Of("GoLang").ToUpper().String()
godump.Dump(v)
// #string GOLANG
func (String) Trim ¶
Trim trims leading and trailing characters. If cutset is empty, trims Unicode whitespace. @group Cleanup
Example: trim whitespace
v := str.Of(" GoForj ").Trim("").String()
godump.Dump(v)
// #string GoForj
func (String) TrimLeft ¶
TrimLeft trims leading characters. If cutset is empty, trims Unicode whitespace. @group Cleanup
Example: trim left
v := str.Of(" GoForj ").TrimLeft("").String()
godump.Dump(v)
// #string GoForj
func (String) TrimRight ¶
TrimRight trims trailing characters. If cutset is empty, trims Unicode whitespace. @group Cleanup
Example: trim right
v := str.Of(" GoForj ").TrimRight("").String()
godump.Dump(v)
// #string GoForj
func (String) UcFirst ¶
UcFirst returns the string with the first rune upper-cased. @group Case
Example: uppercase first rune
v := str.Of("gopher").UcFirst().String()
godump.Dump(v)
// #string Gopher
func (String) UcSplit ¶
UcSplit splits the string on uppercase boundaries and delimiters, returning segments. @group Split
Example: split on upper-case boundaries
v := str.Of("HTTPRequestID").UcSplit()
godump.Dump(v)
// #[]string [HTTP Request ID]
func (String) UcWords ¶
UcWords uppercases the first rune of each word, leaving the rest unchanged. Words are sequences of letters/digits. @group Case
Example: uppercase each word start
v := str.Of("hello WORLD").UcWords().String()
godump.Dump(v)
// #string Hello WORLD
func (String) Unwrap ¶
Unwrap removes matching before and after strings if present. @group Affixes
Example: unwrap string
v := str.Of("\"GoForj\"").Unwrap("\"", "\"").String()
godump.Dump(v)
// #string GoForj
func (String) WordCount ¶
WordCount returns the number of word tokens (letters/digits runs). @group Words
Example: count words
v := str.Of("Hello, world!").WordCount()
godump.Dump(v)
// #int 2
func (String) Words ¶
Words limits the string to count words, appending suffix if truncated. @group Words
Example: limit words
v := str.Of("Perfectly balanced, as all things should be.").Words(3, " >>>").String()
godump.Dump(v)
// #string Perfectly balanced as >>>
func (String) Wrap ¶
Wrap surrounds the string with before and after (after defaults to before). @group Affixes
Example: wrap string
v := str.Of("GoForj").Wrap("\"", "").String()
godump.Dump(v)
// #string "GoForj"
func (String) WrapWords ¶
WrapWords wraps the string to the given width on word boundaries, using breakStr between lines. @group Words
Example: wrap words
v := str.Of("The quick brown fox jumped over the lazy dog.").WrapWords(20, "\n").String()
godump.Dump(v)
// #string The quick brown fox\njumped over the lazy\ndog.
Source Files
¶
- after.go
- append.go
- base64.go
- before.go
- between.go
- camel.go
- charat.go
- chop.go
- contains.go
- count.go
- deduplicate.go
- doesnt.go
- dump.go
- endswith.go
- ensure.go
- equals.go
- excerpt.go
- firstword.go
- headline.go
- helpers.go
- index.go
- is.go
- isascii.go
- isempty.go
- ismatch.go
- join.go
- kebab.go
- lastword.go
- lcfirst.go
- len.go
- limit.go
- mask.go
- newline.go
- pad.go
- pascal.go
- prepend.go
- remove.go
- repeat.go
- replace.go
- reverse.go
- slug.go
- snake.go
- split.go
- splitwords.go
- squish.go
- startswith.go
- string.go
- take.go
- title.go
- tolower.go
- totitle.go
- toupper.go
- trim.go
- ucfirst.go
- ucsplit.go
- ucwords.go
- wordcount.go
- words.go
- wrap.go
- wrapwords.go