Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenRandom ¶
GenRandom generates a random string of the specified length.
Parameters:
length: The length of the random string to be generated.
Returns:
string: The generated random string. error: An error if the random string generation fails.
Example:
str, err := GenRandom(10)
if err != nil {
log.Fatalf("failed to generate random string: %v", err)
}
log.Printf("Generated random string: %s\n", str)
func InSlice ¶
InSlice determines if a specified string exists in a provided slice.
Parameters:
strToFind: The string to search for in the slice. inputSlice: The slice of strings to be searched.
Returns:
bool: true if the string is found in the slice, false otherwise.
Example:
slice := []string{"apple", "banana", "cherry"} isFound := InSlice("banana", slice)
if isFound {
log.Println("Found the string in the slice.")
}
func IsNumeric ¶
IsNumeric checks if a given string is composed entirely of numeric characters (0-9). It iterates over each character in the string and checks if it can be converted to an integer without error. If all characters are numeric, the function returns true; otherwise, it returns false.
Parameters:
s: A string to check for numeric characters.
Returns:
bool: Returns true if the string is numeric, false otherwise.
Example:
str := "1234" isNum := str.IsNumeric(str)
if !isNum {
log.Printf("The string %s is not numeric.\n", str)
}
func SlicesEqual ¶
SlicesEqual compares two slices of strings for equality.
Parameters:
a: The first string slice to be compared. b: The second string slice to be compared.
Returns:
bool: true if the slices are equal (same length and same values), false otherwise.
Example:
a := []string{"apple", "banana", "cherry"} b := []string{"apple", "banana", "cherry"} isEqual := SlicesEqual(a, b)
if isEqual {
log.Println("The string slices are equal.")
} else {
log.Println("The string slices are not equal.")
}
func ToInt64 ¶
ToInt64 converts a string to an int64.
Parameters:
value: The string to be converted to int64.
Returns:
int64: The int64 equivalent of the string. error: An error if the string to int64 conversion fails.
Example:
num, err := ToInt64("1234567890")
if err != nil {
log.Fatalf("failed to convert string to int64: %v", err)
}
log.Printf("Converted string to int64: %d\n", num)
func ToSlice ¶
ToSlice converts a string to a slice of strings, using the specified delimiter.
Parameters:
delimStr: The string to be split into a slice. delim: The delimiter to be used for splitting the string.
Returns:
[]string: A slice of strings obtained by splitting the input string.
Example:
slice := ToSlice("apple,banana,cherry", ",")
for _, str := range slice {
log.Println(str)
}
Types ¶
This section is empty.