strings

package
v0.31.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const AlphaAll = AlphaLower + AlphaUpper + AlphaNum
View Source
const AlphaLower = "abcdefghijklmnopqrstuvwxyz"
View Source
const AlphaNum = "0123456789"
View Source
const AlphaUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
View Source
const Token68 = AlphaAll + "-._~+/"

Variables

This section is empty.

Functions

func AtoInt64 added in v0.19.0

func AtoInt64(s string) int64

AtoInt64 converts a string to Int64.

func AtoUint added in v0.19.0

func AtoUint(s string) uint

AtoUint converts a string to uint.

func AtoUint64 added in v0.19.0

func AtoUint64(s string) uint64

AtoUint64 converts a string to uint64.

func CamelToKebab added in v0.27.0

func CamelToKebab(camelCase string) string

CamelToKebab converts a camel case string to kebab case. If it encounters a character that is not legitimate camel case, it ignores it (like numbers, spaces, etc.). Runs of upper case letters are treated as one word.

Example
a := CamelToKebab("AbcDef")
fmt.Println(a)
b := CamelToKebab("AbcDEFghi")
fmt.Println(b)
Output:

abc-def
abc-de-fghi

func CamelToSnake added in v0.27.0

func CamelToSnake(camelCase string) string

CamelToSnake converts a camel case string to snake case. If it encounters a character that is not legitimate camel case, it ignores it (like numbers, spaces, etc.). Runs of upper case letters are treated as one word. A run of upper case, followed by lower case letters will be treated as if the final character in the upper case run belong with the lower case letters.

Example
a := CamelToSnake("AbcDef")
fmt.Println(a)
b := CamelToSnake("AbcDEFghi")
fmt.Println(b)
Output:

abc_def
abc_de_fghi

func ContainsAnyStrings added in v0.13.4

func ContainsAnyStrings(haystack string, needles ...string) bool

ContainsAnyStrings returns true if the haystack contains any of the needles

func CryptoString added in v0.20.0

func CryptoString(source string, n int) string

CryptoString returns a cryptographically secure random string from the given source. Use AlphaAll, AlphaUpper, AlphaLower, or AlphaNum as shortcuts for source.

func EndsWith

func EndsWith(s string, ending string) bool

EndsWith returns true if the string ends with the ending string.

func ExtractNumbers added in v0.7.1

func ExtractNumbers(in string) (out string)

ExtractNumbers returns a string with the digits contained in the given string.

Example
a := ExtractNumbers("a1b2 c3")
fmt.Println(a)
Output:

123

func HasCharType added in v0.19.0

func HasCharType(s string, wantUpper, wantLower, wantDigit, wantPunc, wantSymbol bool) bool

HasCharType returns true if the given string has at least one of all the selected char types.

func HasOnlyLetters added in v0.7.0

func HasOnlyLetters(s string) bool

HasOnlyLetters will return false if any of the characters in the string do not pass the unicode.IsLetter test.

func If added in v0.12.0

func If(cond bool, trueVal, falseVal string) string

If is like the ternary operator ?. It returns the first string on true, and the second on false.

func Indent added in v0.2.0

func Indent(s string) string

Indent will indent every line of the string with a tab

func JoinContent added in v0.7.0

func JoinContent(sep string, items ...string) string

JoinContent joins strings together with the separator sep. Only strings that are not empty strings are joined.

Example
a := JoinContent("+", "this", "", "that")
fmt.Println(a)
Output:

this+that

func KebabToCamel added in v0.2.4

func KebabToCamel(s string) string

KebabToCamel convert kebab-case words to CamelCase words.

Example
a := KebabToCamel("abc-def")
fmt.Println(a)
Output:

AbcDef

func LcFirst

func LcFirst(s string) string

LcFirst makes sure the first character in the string is lower case.

func PasswordString added in v0.9.3

func PasswordString(n int) string

PasswordString generates a pseudo random password with the given length using characters that are common in passwords. We attempt to leave out letters that are easily visually confused. Specific letters excluded are lowercase l, upper case I and the number 1, upper case O and the number 0 Also, only easily identifiable and describable symbols are used. It also tries to protect against accidentally creating an easily guessed value by making sure the password has at least one lower-case letter, one upper-case letter, one number, and one symbol. n must be at least 4

func RandomString added in v0.9.3

func RandomString(source string, n int) string

RandomString generates a pseudo random string of the given length using the given characters. The distribution is not perfect, but works for general purposes

func ReplaceStrings added in v0.27.3

func ReplaceStrings(s string, searchList []string, replaceList []string) string

ReplaceStrings is a memory efficient string replacer, replacing every string in the searchList with the matching string in the replaceList.

func SnakeToKebab added in v0.9.3

func SnakeToKebab(s string) string

SnakeToKebab converts snake_case words to kebab-case words.

Example
a := SnakeToKebab("abc_def")
fmt.Println(a)
Output:

abc-def

func StartsWith

func StartsWith(s string, beginning string) bool

StartsWith returns true if the string begins with the beginning string.

func Title added in v0.2.0

func Title(s string) string

Title is a more advanced titling operation. It will convert underscores to spaces, and add spaces to CamelCase words.

Example
a := Title("do_i_seeYou")
fmt.Println(a)
Output:

Do I See You

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL