Documentation ¶
Index ¶
- Constants
- Variables
- func AddSlashes(str string) string
- func Bin2Hex(str string) (encoded string)
- func Chr(codepoint int) string
- func ChunkSplit(str string, args ...any) (result string, err error)
- func Explode(separator string, str string, limit ...int) ([]string, error)
- func Hex2Bin(encoded string) (str string, err error)
- func Implode[T any](array []T, sep ...string) string
- func Lcfirst(str string) string
- func Levenshtein(str1 string, str2 string, cost ...int) int
- func Ltrim(str string, chars ...string) (string, error)
- func Md5(str string, raw ...bool) (res string)
- func NumberFormat(num float64, options ...string) (string, error)
- func Rtrim(str string, chars ...string) (string, error)
- func StrContains(haystack, needle string) bool
- func StrPad(s string, length int, args ...any) (string, error)
- func StrReplace(find, replace, str interface{}) (interface{}, int, error)
- func StrShuffle(str string) string
- func StrSplit(s string, length ...int) ([]string, error)
- func StrStartsWith(haystack, needle string) bool
- func Strchr(str string, search interface{}, beforeSearch ...bool) (string, error)
- func Strlen(str string) int
- func Strpos(str, find string, offset ...int) (int, error)
- func Strrev(s string) string
- func Strrpos(haystack, needle string, offset ...int) (int, error)
- func Trim(str string, chars ...string) (string, error)
- func Ucfirst(str string) string
- func Ucwords(str string) string
Constants ¶
const ( STR_PAD_RIGHT int = iota STR_PAD_LEFT STR_PAD_BOTH )
Variables ¶
var ( ErrLengthNotValid = errors.New("length is not valid") ErrLengthMustGreaterThanZero = errors.New("length must be greater than zero") ErrSeparatorNotValid = errors.New("separator is not valid") )
var ( ErrTooManyArgs = errors.New("too many args") ErrPadTypeInvalid = errors.New("invalid pad type") ErrPadInvalid = errors.New("invalid pad") ErrPadMustNotEmptyString = errors.New("pad must be a non-empty string") )
var ( ErrStrchrInvalidParameterType = errors.New("invalid parameter type") ErrStrchrStringNotFound = errors.New("string not found") )
var ( ErrStrposInvalidOffset = errors.New("offset is greather than length of string") ErrStrposStringNotFound = errors.New("string not found") )
var ( ErrStrrposInvalidOffset = errors.New("offset is greather than length of string") ErrStrrposStringNotFound = errors.New("string is not found") )
var (
ErrLTrimInvalidRange = errors.New("invalid character range")
)
var (
ErrRTrimInvalidRange = errors.New("invalid character range")
)
var (
ErrStrReplaceInvalidParameter = errors.New("must be given parameter correctly")
)
var (
ErrTrimInvalidRange = errors.New("invalid character range")
)
Functions ¶
func AddSlashes ¶
AddSlashes returns a string with backslashes added before characters that need to be escaped. These characters are: \\ " and \'
func Bin2Hex ¶
The bin2hex() function converts a string of ASCII characters to hexadecimal values. Parameter: - str => string to be converted Return: - encoded => converted string
func Chr ¶
Chr is a function that returns a character from a number. Parameter : - codepoint => it can be in decimal, octal, or hex values. Return : - single-byte string
func ChunkSplit ¶
ChunkSplit - Split a string into smaller chunks php doc: https://www.php.net/manual/en/function.chunk-split
func Explode ¶
The Explode function breaks a string into an array. Parameter : - separator => Specifies where to break the string. - str => The string to split. - limit => Specifies the number of array elements to return. If the separator is empty then the function returns an error with the error message `Separator cannot be empty`. If the limit is greater than the length of an element after a split, then return all elements. If the limit is less than the minus length of an element after a split, then return all elements. if the limit is empty or null then return all elements. If the limit is greater than 0, then an array/slice with a maximum of limit elements is returned. If the limit is less than 0, then an array/slice with a maximum of limit elements is returned. If the limit is 0, return the result as an array/slice with a single element. Return : - The array/slice with all elements.
func Hex2Bin ¶
The hex2bin() function converts a string of hexadecimal values to ASCII characters. Parameter -encoded => hexadecimal value to be converted Return - str => string of ASCII characters - error => error if encoded string contain non hexadecimal character
func Implode ¶
The Implode function joins array/slice element with a string. Parameter : - array => The array/slice to join to a string. - separator => Specifies what to put between the array elements. Return : - The string with all array/slice elements joined.
func Lcfirst ¶
The Lcfirst() function converts the first character of a string to lowercase. Parameter - str => string to be converted Return - res => converted string
func Levenshtein ¶
Levenshtein calculates the distance between two strings. This algorithm allow insertions, deletions and substitutions to change one string to the second Compatible with non-ASCII characters
func Ltrim ¶
The Ltrim() function removes whitespace or other predefined characters from the left side of a string. Parameters
- str => specifies the string to check
- chars (optional) => Specifies which characters to remove from the string. if omitted, ordinary whitespace, tab, new line, vertical tab, and carriage return are removed
Return - res => modified string - err => error if given range is invalid
func Md5 ¶
The Md5() function calculates the MD5 hash of a string. Parameter
- str => string to be calculated
- raw => (optional). Specifies hex or binary output format: TRUE: Raw 16 character binary format FALSE: Default. 32 character hex number
Return - res => calculated MD5 hash
func NumberFormat ¶
NumberFormat is for formats a number with grouped thousands and optionally decimal digits.
num : The number being formatted. option 1 : Sets the number of decimal digits. If 0, the decimal_separator is omitted from the return value. Default = 0 option 2 : Sets the separator for the decimal point. Default = "." option 3 : Sets the thousands separator. Default = "," The behaviour of this function is like https://www.php.net/manual/en/function.number-format.php
func Rtrim ¶
The RTrim() function removes whitespace or other predefined characters from the right side of a string. Parameters
- str => specifies the string to check
- chars (optional) => Specifies which characters to remove from the string. if omitted, ordinary whitespace, tab, new line, vertical tab, and carriage return are removed
Return - res => modified string - err => error if given range is invalid
func StrContains ¶
The StrContains() function checks if a string contains a specified string. Parameters - haystack => the string to search in. - needle => the string to search for. Returns - bool => true if the string contains the search value, false otherwise.
func StrPad ¶
StrPad Pad a string to a certain length with another string This function returns the string string padded on the left, the right, or both sides to the specified padding length. If the optional argument pad_string is not supplied, the string is padded with spaces, otherwise it is padded with characters from pad_string up to the limit. Optional params: - pad_string => string or int or float64 - pad_type => STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH php doc: https://www.php.net/manual/en/function.str-pad.php
func StrReplace ¶
The StrReplace() function replaces some characters with some other characters in a string. but it has a bit different than PHP does: 1. it not allowed if parameters has nested slice. 2. parameters can only be string or []string, so if you must convert it first into string like PHP does. 3. you can get a count of the number of replacements in return value. Parameters - find => value to find. - replace => value to replace the value in 'find'. - str => value to be searched. Returns - interface{} => string or an slice with replaced values - int => count of the number of replacements - error => errors if parameter is invalid
func StrShuffle ¶
StrShuffle Randomly shuffles a string php doc: https://www.php.net/manual/en/function.str-shuffle
func StrSplit ¶
StrSplit is to convert a string to an array If the optional length parameter is specified, the returned array will be broken down into chunks with each being length in length, except the final chunk which may be shorter if the string does not divide evenly. The default length is 1, meaning every chunk will be one byte in size. If length is less than 1, a nil array and error errMust2Params will be thrown. The behaviour of this function is like https://www.php.net/manual/en/function.str-split.php
func StrStartsWith ¶
func Strchr ¶
The Strchr() function searches for the first occurrence of a string inside another string. Parameter
- str => string to search
- search => Specifies the string to search for. If this parameter is a number, it will search for the character matching the ASCII value of the number
- beforeSearch => Optional. A boolean value whose default is "false". If set to "true", it returns the part of the string before the first occurrence of the search parameter.
Returns - string => Returns the rest of the string (from the matching point) - error => either string not found, or the parameter search is invalid
func Strlen ¶
Then Strlen() function calculates the length of the given string like php does. Parameter
- str => string to calculate the length
Returns
- int => the length of the string
func Strpos ¶
The Strpos() function finds the position of the first occurrence of a string inside another string. Parameters - str => Specifies the string to search - find => String to be find - offset => (optional). Specifies where to begin the search. If start is a negative number, it counts from the end of the string. Returns - int => Returns the position of the first occurrence of a string - error => errors if the given offsed is invalid or if string not found
func Strrev ¶
Strrev is a function that reverses a string. Parameter : - s => The string to reverse Return : - The reversed string
func Strrpos ¶
The Strrpos() function finds the position of the last occurrence of a string inside another string. Parameters
- haystack => The string to search in.
- needle => Specifies the string to find
- offset => If zero or positive, the search is performed left to right skipping the first offset bytes of the haystack. If negative, the search is performed right to left skipping the last offset bytes of the haystack and searching for the first occurrence of needle.
Types ¶
This section is empty.
Source Files ¶
- add_slashes.go
- bin_2_hex.go
- chr.go
- chunk_split.go
- explode.go
- hex_2_bin.go
- implode.go
- l_trim.go
- lcfirst.go
- levenshtein.go
- md5.go
- number_format.go
- r_trim.go
- str_contains.go
- str_pad.go
- str_replace.go
- str_shuffle.go
- str_split.go
- str_starts_with.go
- strchr.go
- strlen.go
- strpos.go
- strrev.go
- strrpos.go
- trim.go
- ucfirst.go
- ucwords.go