gf: github.com/gogf/gf/g/text/gstr Index | Files

package gstr

import "github.com/gogf/gf/g/text/gstr"

Package gstr provides functions for string handling.

Index

Package Files

gstr.go gstr_levenshtein.go gstr_parse.go gstr_pos.go gstr_similartext.go gstr_soundex.go gstr_trim.go

func AddSlashes Uses

func AddSlashes(str string) string

AddSlashes quotes chars('"\) with slashes.

func Chr Uses

func Chr(ascii int) string

Chr return the ascii string of a number(0-255).

func ChunkSplit Uses

func ChunkSplit(body string, chunkLen int, end string) string

ChunkSplit splits a string into smaller chunks. Can be used to split a string into smaller chunks which is useful for e.g. converting BASE64 string output to match RFC 2045 semantics. It inserts end every chunkLen characters.

func Compare Uses

func Compare(a, b string) int

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.

func Contains Uses

func Contains(str, substr string) bool

Contains reports whether <substr> is within <str>, case-sensitively.

func ContainsAny Uses

func ContainsAny(s, chars string) bool

ContainsAny reports whether any Unicode code points in <chars> are within <s>.

func ContainsI Uses

func ContainsI(str, substr string) bool

ContainsI reports whether substr is within str, case-insensitively.

func Count Uses

func Count(s, substr string) int

Count counts the number of <substr> appears in <s>. It returns 0 if no <substr> found in <s>.

func CountChars Uses

func CountChars(str string, noSpace ...bool) map[string]int

CountChars returns information about chars' count used in a string.

func CountI Uses

func CountI(s, substr string) int

CountI counts the number of <substr> appears in <s>, case-insensitively. It returns 0 if no <substr> found in <s>.

func CountWords Uses

func CountWords(str string) map[string]int

CountWords returns information about words' count used in a string.

func Equal Uses

func Equal(a, b string) bool

Equal reports whether <a> and <b>, interpreted as UTF-8 strings, are equal under Unicode case-folding, case-insensitively.

func Explode Uses

func Explode(delimiter, str string) []string

Explode splits string <str> by a string <delimiter>, to an array. See http://php.net/manual/en/function.explode.php.

func Fields Uses

func Fields(str string) []string

Fields returns the words used in a string as slice.

func HideStr Uses

func HideStr(str string, percent int, hide string) string

HideStr replaces part of the the string <str> to <hide> by <percentage> from the <middle>.

func Implode Uses

func Implode(glue string, pieces []string) string

Implode joins array elements <pieces> with a string <glue>. http://php.net/manual/en/function.implode.php

func InArray Uses

func InArray(a []string, s string) bool

InArray checks whether string <s> in slice <a>.

func IsLetterLower Uses

func IsLetterLower(b byte) bool

IsLetterLower tests whether the given byte b is in lower case.

func IsLetterUpper Uses

func IsLetterUpper(b byte) bool

IsLetterUpper tests whether the given byte b is in upper case.

func IsNumeric Uses

func IsNumeric(s string) bool

IsNumeric tests whether the given string s is numeric.

func Join Uses

func Join(array []string, sep string) string

Join concatenates the elements of a to create a single string. The separator string sep is placed between elements in the resulting string.

func LcFirst Uses

func LcFirst(s string) string

LcFirst returns a copy of the string s with the first letter mapped to its lower case.

func Levenshtein Uses

func Levenshtein(str1, str2 string, costIns, costRep, costDel int) int

Levenshtein calculates Levenshtein distance between two strings. costIns: Defines the cost of insertion. costRep: Defines the cost of replacement. costDel: Defines the cost of deletion. See http://php.net/manual/en/function.levenshtein.php.

func Nl2Br Uses

func Nl2Br(str string, isXhtml ...bool) string

Nl2Br inserts HTML line breaks(<br>|<br />) before all newlines in a string: \n\r, \r\n, \r, \n.

func NumberFormat Uses

func NumberFormat(number float64, decimals int, decPoint, thousandsSep string) string

NumberFormat formats a number with grouped thousands. <decimals>: Sets the number of decimal points. <decPoint>: Sets the separator for the decimal point. <thousandsSep>: Sets the thousands separator. See http://php.net/manual/en/function.number-format.php.

func Ord Uses

func Ord(char string) int

Ord converts the first byte of a string to a value between 0 and 255.

func Parse Uses

func Parse(s string) (result map[string]interface{}, err error)

Parse parses the string into map[string]interface{}.

f1=m&f2=n -> map[f1:m f2:n] f[a]=m&f[b]=n -> map[f:map[a:m b:n]] f[a][a]=m&f[a][b]=n -> map[f:map[a:map[a:m b:n]]] f[]=m&f[]=n -> map[f:[m n]] f[a][]=m&f[a][]=n -> map[f:map[a:[m n]]] f[][]=m&f[][]=n -> map[f:[map[]]] // Currently does not support nested slice. f=m&f[a]=n -> error a .[[b=c -> map[a___[b:c]

func Pos Uses

func Pos(haystack, needle string, startOffset ...int) int

Pos returns the position of the first occurrence of <needle> in <haystack> from <startOffset>, case-sensitively. It returns -1, if not found.

func PosI Uses

func PosI(haystack, needle string, startOffset ...int) int

PosI returns the position of the first occurrence of <needle> in <haystack> from <startOffset>, case-insensitively. It returns -1, if not found.

func PosR Uses

func PosR(haystack, needle string, startOffset ...int) int

PosR returns the position of the last occurrence of <needle> in <haystack> from <startOffset>, case-sensitively. It returns -1, if not found.

func PosRI Uses

func PosRI(haystack, needle string, startOffset ...int) int

PosRI returns the position of the last occurrence of <needle> in <haystack> from <startOffset>, case-insensitively. It returns -1, if not found.

func QuoteMeta Uses

func QuoteMeta(str string) string

QuoteMeta returns a version of str with a backslash character (\) before every character that is among: .\+*?[^]($)

func Repeat Uses

func Repeat(input string, multiplier int) string

Repeat returns a new string consisting of multiplier copies of the string input.

func Replace Uses

func Replace(origin, search, replace string, count ...int) string

Replace returns a copy of the string <origin> in which string <search> replaced by <replace> case-sensitively.

func ReplaceByArray Uses

func ReplaceByArray(origin string, array []string) string

ReplaceByArray returns a copy of <origin>, which is replaced by a slice in order, case-sensitively.

func ReplaceByMap Uses

func ReplaceByMap(origin string, replaces map[string]string) string

ReplaceByMap returns a copy of <origin>, which is replaced by a map in unordered way, case-sensitively.

func ReplaceI Uses

func ReplaceI(origin, search, replace string, count ...int) string

Replace returns a copy of the string <origin> in which string <search> replaced by <replace> case-insensitively.

func ReplaceIByArray Uses

func ReplaceIByArray(origin string, array []string) string

ReplaceIByArray returns a copy of <origin>, which is replaced by a slice in order, case-insensitively.

func ReplaceIByMap Uses

func ReplaceIByMap(origin string, replaces map[string]string) string

ReplaceIByMap returns a copy of <origin>, which is replaced by a map in unordered way, case-insensitively.

func Reverse Uses

func Reverse(str string) string

Reverse returns a string which is the reverse of <str>.

func RuneLen Uses

func RuneLen(str string) int

RuneLen returns string length of unicode.

func SearchArray Uses

func SearchArray(a []string, s string) int

SearchArray searches string <s> in string slice <a> case-sensitively, returns its index in <a>. If <s> is not found in <a>, it returns -1.

func Shuffle Uses

func Shuffle(str string) string

Shuffle randomly shuffles a string.

func SimilarText Uses

func SimilarText(first, second string, percent *float64) int

SimilarText calculates the similarity between two strings. See http://php.net/manual/en/function.similar-text.php.

func Soundex Uses

func Soundex(str string) string

Soundex calculates the soundex key of a string. See http://php.net/manual/en/function.soundex.php.

func Split Uses

func Split(str, delimiter string) []string

Split splits string <str> by a string <delimiter>, to an array.

func Str Uses

func Str(haystack string, needle string) string

Str returns part of <haystack> string starting from and including the first occurrence of <needle> to the end of <haystack>. See http://php.net/manual/en/function.strstr.php.

func StrLimit Uses

func StrLimit(str string, length int, suffix ...string) string

StrLimit returns a portion of string <str> specified by <length> parameters, if the length of <str> is greater than <length>, then the <suffix> will be appended to the result string.

func StripSlashes Uses

func StripSlashes(str string) string

StripSlashes un-quotes a quoted string by AddSlashes.

func SubStr Uses

func SubStr(str string, start int, length ...int) (substr string)

SubStr returns a portion of string <str> specified by the <start> and <length> parameters.

func ToLower Uses

func ToLower(s string) string

ToLower returns a copy of the string s with all Unicode letters mapped to their lower case.

func ToUpper Uses

func ToUpper(s string) string

ToUpper returns a copy of the string s with all Unicode letters mapped to their upper case.

func Trim Uses

func Trim(str string, characterMask ...string) string

Trim strips whitespace (or other characters) from the beginning and end of a string.

func TrimLeft Uses

func TrimLeft(str string, characterMask ...string) string

TrimLeft strips whitespace (or other characters) from the beginning of a string.

func TrimLeftStr Uses

func TrimLeftStr(str string, cut string) string

TrimLeftStr strips all of the given <cut> string from the beginning of a string.

func TrimRight Uses

func TrimRight(str string, characterMask ...string) string

TrimRight strips whitespace (or other characters) from the end of a string.

func TrimRightStr Uses

func TrimRightStr(str string, cut string) string

TrimRightStr strips all of the given <cut> string from the end of a string.

func UcFirst Uses

func UcFirst(s string) string

UcFirst returns a copy of the string s with the first letter mapped to its upper case.

func UcWords Uses

func UcWords(str string) string

UcWords uppercase the first character of each word in a string.

func WordWrap Uses

func WordWrap(str string, width int, br string) string

WordWrap wraps a string to a given number of characters. TODO: Enable cut param, see http://php.net/manual/en/function.wordwrap.php.

Package gstr imports 9 packages (graph) and is imported by 22 packages. Updated 2019-06-19. Refresh now. Tools for package owners.