Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenRandom ¶
GenRandom generates a random string of a specified length.
**Parameters:**
length: Length of the random string to be generated.
**Returns:**
string: Generated random string. error: An error if random string generation fails.
Example ¶
package main import ( "fmt" "log" "github.com/l50/goutils/v2/str" ) func main() { randStr, err := str.GenRandom(10) if err != nil { log.Fatalf("failed to generate random string: %v", err) } fmt.Printf("Generated random string: %s\n", randStr) }
Output:
func InSlice ¶
InSlice determines if a specified string exists in a given slice.
**Parameters:**
strToFind: String to search for in the slice. inputSlice: Slice of strings to be searched.
**Returns:**
bool: true if string is found in the slice, false otherwise.
Example ¶
package main import ( "fmt" "github.com/l50/goutils/v2/str" ) func main() { slice := []string{"apple", "banana", "cherry"} isFound := str.InSlice("banana", slice) fmt.Println(isFound) }
Output: true
func IsNumeric ¶
IsNumeric checks if a string is entirely composed of numeric characters.
**Parameters:**
s: String to check for numeric characters.
**Returns:**
bool: true if the string is numeric, false otherwise.
Example ¶
package main import ( "fmt" "github.com/l50/goutils/v2/str" ) func main() { isNum := str.IsNumeric("1234") fmt.Println(isNum) }
Output: true
func SlicesEqual ¶
SlicesEqual compares two slices of strings for equality.
**Parameters:**
a: First string slice for comparison. b: Second string slice for comparison.
**Returns:**
bool: true if slices are equal, false otherwise.
Example ¶
package main import ( "fmt" "github.com/l50/goutils/v2/str" ) func main() { a := []string{"apple", "banana", "cherry"} b := []string{"apple", "banana", "cherry"} isEqual := str.SlicesEqual(a, b) fmt.Println(isEqual) }
Output: true
func StripANSI ¶ added in v2.2.1
StripANSI removes ANSI escape codes from a string.
**Parameters:**
str: String to remove ANSI escape codes from.
**Returns:**
string: String with ANSI escape codes removed.
func ToInt64 ¶
ToInt64 converts a string to int64.
**Parameters:**
value: String to be converted to int64.
**Returns:**
int64: int64 equivalent of the string. error: An error if the conversion fails.
Example ¶
package main import ( "fmt" "log" "github.com/l50/goutils/v2/str" ) func main() { num, err := str.ToInt64("1234567890") if err != nil { log.Fatalf("failed to convert string to int64: %v", err) } fmt.Printf("Converted string to int64: %d\n", num) }
Output: Converted string to int64: 1234567890
func ToSlice ¶
ToSlice converts a string to a slice of strings using a delimiter.
**Parameters:**
delimStr: String to be split into a slice. delim: Delimiter to be used for splitting the string.
**Returns:**
[]string: Slice of strings from the split input string.
Example ¶
package main import ( "fmt" "github.com/l50/goutils/v2/str" ) func main() { slice := str.ToSlice("apple,banana,cherry", ",") fmt.Println(slice) }
Output: [apple banana cherry]
Types ¶
This section is empty.