string

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(s string) string

CamelCase converts a string to CamelCase format. It capitalizes the first letter of each word (except the first word), removes spaces and punctuation, and lower cases the rest of the letters.

func Capitalize

func Capitalize(s string) string

Capitalize the first letter of a string and leaves the rest unchanged.

func EndsWith

func EndsWith(str, target string, position ...int) (bool, error)

EndsWith checks if the string 'str' ends with the target string 'target' optionally up to a specified 'position' in 'str'. It returns true if 'str' ends with 'target', and false otherwise. If 'position' is provided, only the characters up to that position in 'str' are considered.

func Escape

func Escape(s string) string

Escape converts special characters in a string to their corresponding HTML entities. It returns the escaped string where special characters are replaced by their entities.

func KebabCase

func KebabCase(s string) (string, error)

KebabCase converts a string to kebab-case format, where words are separated by hyphens. It removes spaces, punctuation, and converts letters to lowercase. Returns the kebab-case string and an error if the input string is empty.

func LowerCase

func LowerCase(s string) (string, error)

LowerCase converts a string to kebab-case format, where words are separated by hyphens. It removes spaces, punctuation, and converts letters to lowercase. Returns the kebab-case string and an error if the input string is empty.

func LowerFirst

func LowerFirst(s string) string

LowerFirst converts the first letter of a string to lowercase while leaving the rest unchanged.

func Pad

func Pad(s string, length int, char ...string) string

Pad a string 's' with a specified 'length' by adding 'chars' on both sides. If 'char' is not provided, it defaults to a space character. The resulting padded string will have a total length of at least 'length'. If the original string length is greater than or equal to 'length', the original string is returned unchanged.

func PadEnd

func PadEnd(s string, length int, char ...string) string

PadEnd pads a string 's' with a specified 'length' by adding 'char' at the end. If 'char' is not provided, it defaults to a space character. The resulting padded string will have a total length of at least 'length'. If the original string length is greater than or equal to 'length', the original string is returned unchanged.

func PadStart

func PadStart(s string, length int, char ...string) string

PadStart pads a string 's' with a specified 'length' by adding 'char' at the beginning. If 'char' is not provided, it defaults to a space character. The resulting padded string will have a total length of at least 'length'. If the original string length is greater than or equal to 'length', the original string is returned unchanged.

func ParseInt

func ParseInt(s string) (int, error)

ParseInt parses an integer from the given string 's'. It returns the parsed integer value and an error if parsing fails.

func Repeat

func Repeat(s string, times int) string

Repeat the given string 's' a specified number of 'times'. It returns the concatenated string where 's' is repeated 'times' times. If 'times' is zero or negative, an empty string is returned.

func Replace

func Replace(s, pattern, replacement string) string

Replace occurrences of a specified 'pattern' in the string 's' with the 'replacement' string. It returns the modified string where all occurrences of 'pattern' are replaced with 'replacement'.

func SnakeCase

func SnakeCase(s string) string

SnakeCase converts a string to snake_case format. It replaces spaces and punctuation with underscores and converts letters to lowercase.

func Split

func Split(s, separator string, limit int) []string

Split a string 's' into substrings using the specified 'separator'. It returns a slice of substrings. The 'limit' parameter controls the maximum number of substrings to return. If 'limit' is negative, there is no limit.

func StartsWith

func StartsWith(str, target string, position ...int) (bool, error)

StartsWith checks if the string 'str' starts with the target string 'target' optionally from the specified 'position' in 'str'. It returns true if 'str' starts with 'target', and false otherwise. If 'position' is provided, the comparison starts from that position in 'str'.

func Unescape

func Unescape(s string) string

Unescape a string that contains Escape sequences and returns the unescaped string. The input string should be surrounded by double quotes to properly Unescape it. If un-escaping fails, the original input string is returned.

func UpperCase

func UpperCase(s string) (string, error)

UpperCase converts all characters in the input string 's' to uppercase. It returns the modified string with all characters in uppercase.

func UpperFirst

func UpperFirst(s string) string

UpperFirst converts the first letter of a string to uppercase while leaving the rest unchanged.

Types

This section is empty.

Jump to

Keyboard shortcuts

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