Documentation ¶
Overview ¶
Package strutil provides methods for working with strings
Index ¶
- Variables
- func After(s, substr string) string
- func Before(s, substr string) string
- func Concat(s ...string) string
- func Copy(v string) string
- func Ellipsis(s string, maxSize int) string
- func Exclude(data, substr string) string
- func Extract(s string, start, end int) string
- func Fields(data string) []string
- func HasPrefixAny(s string, prefix ...string) bool
- func HasSuffixAny(s string, suffix ...string) bool
- func Head(s string, n int) string
- func Len(s string) int
- func PrefixSize(str string, prefix rune) int
- func Q(v ...string) string
- func ReadField(data string, index int, multiSep bool, separators ...string) string
- func ReplaceAll(source, from, to string) string
- func Substr(s string, start, length int) string
- func Substring(s string, start, end int) string
- func SuffixSize(str string, suffix rune) int
- func Tail(s string, n int) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var EllipsisSuffix = "..."
EllipsisSuffix is ellipsis suffix
Functions ¶
func After ¶
After returns part of the string after given substring
Example ¶
fmt.Println(After("john@domain.com", "@"))
Output: domain.com
func Before ¶
Before returns part of the string before given substring
Example ¶
fmt.Println(Before("john@domain.com", "@"))
Output: john
func Concat ¶
Concat is method for fast string concatenation
Example ¶
fmt.Println(Concat("abc", " ", "123", " ", "ABC"))
Output: abc 123 ABC
func Ellipsis ¶
Ellipsis trims given string (unicode supported)
Example ¶
fmt.Println(Ellipsis("This is too long message to show", 18))
Output: This is too lon...
func Exclude ¶
Exclude excludes substring from given string
Example ¶
fmt.Println(Exclude("This is funny message", " funny"))
Output: This is message
func Extract ¶
Extract extracts a substring safely (unicode NOT supported)
Example ¶
fmt.Println(Extract("This is funny message", 8, 13))
Output: funny
func Fields ¶
Fields splits the string data around each instance of one or more consecutive white space or comma characters
Example ¶
fmt.Printf("%#v\n", Fields("Bob Alice, 'Mary Key', \"John Dow\""))
Output: []string{"Bob", "Alice", "Mary Key", "John Dow"}
func HasPrefixAny ¶
HasPrefixAny tests whether the string s begins with one of given prefixes
Example ¶
fmt.Println(HasPrefixAny("www.domain.com", "dl", "www")) fmt.Println(HasPrefixAny("api.domain.com", "dl", "www"))
Output: true false
func HasSuffixAny ¶
HasSuffixAny tests whether the string s ends with one of given suffixes
Example ¶
fmt.Println(HasSuffixAny("www.domain.com", ".com", ".org", ".net")) fmt.Println(HasSuffixAny("www.domain.info", ".com", ".org", ".net"))
Output: true false
func Head ¶
Head returns n first symbols from given string (unicode supported)
Example ¶
fmt.Println(Head("This is funny message", 7))
Output: This is
func Len ¶
Len returns number of symbols in string (unicode supported)
Example ¶
fmt.Println(Len("Пример 例子 例 მაგალითად"))
Output: 21
func PrefixSize ¶
PrefixSize returns prefix size
Example ¶
fmt.Println(PrefixSize("#### Header 4", '#'))
Output: 4
func Q ¶
Q is simple helper for working with default values
Example ¶
var defaultValue = "john" var user = "" fmt.Println(Q(user, defaultValue))
Output: john
func ReadField ¶
ReadField reads field with given index from data
Example ¶
fmt.Println(ReadField("Bob Alice\tJohn Mary", 2, true, " ", "\t")) fmt.Println(ReadField("Bob:::Mary:John:", 3, false, ":"))
Output: John Mary
func ReplaceAll ¶
ReplaceAll replaces all symbols in given string
Example ¶
fmt.Println(ReplaceAll("Message", "es", "?"))
Output: M???ag?
func Substr ¶
Substr returns the part of a string between the start index and a number of characters after it (unicode supported)
Example ¶
fmt.Println(Substr("Пример 例子 例 მაგალითად", 7, 2))
Output: 例子
func Substring ¶
Substring returns the part of the string between the start and end (unicode supported)
Example ¶
fmt.Println(Substring("Пример 例子 例 მაგალითად", 7, 9))
Output: 例子
func SuffixSize ¶
SuffixSize returns suffix size
Example ¶
fmt.Println(SuffixSize("Message ", ' '))
Output: 4
Types ¶
This section is empty.