stringHelpers

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 13 Imported by: 7

README

stringHelpers

stringHelpers provides common string utilities — formatting, quoting, encoding, special-character handling, camel-casing, and comparison.

Functions

Casing and Formatting
Function Description
LowerFirst(s string) string Lowercases the first character
CamelCase(string) string Converts to camelCase
PadRight(s, p string, l int) string Pads string to length on the right
PadLeft(s, p string, l int) string Pads string to length on the left
Array Conversion
Function Description
ArrToString([]string) string Joins array elements with newlines
StrArrayToString([]string) string Joins array elements with newlines
StrArrayToStringWithSep([]string, sep string) string Joins array with a custom separator
Special Characters
Function Description
RemoveSpecialChars(string) string Replaces non-alphanumeric chars with dashes
RemoveSpecialCharacters(string) string Strips all non-letter/digit Unicode chars
ReplaceWildcard(orig, wildcard, replacement string) string Replaces {{wildcard}} patterns in a string
MakeStringStorable(string) string Replaces CR/LF with {cr}/{lf} for storage
MakeStringDisplayable(string) string Reverses MakeStringStorable
Quoting and Wrapping
Function Description
DQuote(s string) string Wraps in double quotes
SQuote(s string) string Wraps in single quotes
DBracket(s string) string Wraps in [[ ]]
SBracket(s string) string Wraps in [ ]
DChevrons(s string) string Wraps in << >>
SChevrons(s string) string Wraps in < >
DCurlies(s string) string Wraps in {{ }}
SCurlies(s string) string Wraps in { }
DParentheses(s string) string Wraps in (( ))
SParentheses(s string) string Wraps in ( )
Encoding and Comparison
Function Description
Encode(string) string SHA3-256 hash of path-safe encoded input
CompareStrings(a, b string) Logs a line-by-line diff between two strings

Example

import "github.com/mt1976/frantic-core/stringHelpers"

func main() {
    fmt.Println(stringHelpers.CamelCase("hello world"))    // "helloWorld"
    fmt.Println(stringHelpers.DQuote("hello"))             // `"hello"`
    fmt.Println(stringHelpers.PadRight("hi", ".", 10))     // "hi........"
    fmt.Println(stringHelpers.RemoveSpecialChars("a@b#c")) // "a-b-c"
}

Documentation

Overview

Package stringHelpers provides common string utilities for formatting and validation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrToString

func ArrToString(strArray []string) string

ArrToString converts an array of strings to a printable string

func CamelCase added in v1.3.4

func CamelCase(s string) string

func CompareStrings added in v1.3.4

func CompareStrings(a, b string)

func DBracket

func DBracket(s string) string

DBracket wraps the string in double brackets - [[]]

func DChevrons

func DChevrons(s string) string

DChevrons wraps the string in double chevrons - <<>>

func DCurlies

func DCurlies(s string) string

DCurlies wraps the string in double curlies - {{}}

func DParentheses

func DParentheses(s string) string

DParentheses wraps the string in double Parentheses - (())

func DQuote

func DQuote(s string) string

DQuote wraps the string in double quotes - ""

func Encode

func Encode(rawStr string) string

Encode encodes a string to base64

func LowerFirst

func LowerFirst(s string) string

Lowers the first character of a string

func MakeStringDisplayable

func MakeStringDisplayable(in string) string

The function "MakeStringDisplayable" takes a string as input and returns a modified version of the string that is displayable. Replaces {{cr}}/{{lf}} with ascii cr/lf.

func MakeStringStorable

func MakeStringStorable(in string) string

The function "MakeStringStorable" takes a string as input and returns a storable version of the string. Replaces ascii cr/lf with {{cr}}/{{lf}}.

func PadLeft

func PadLeft(s string, p string, l int) string

PadLeft pads a string on the left

func PadRight

func PadRight(s string, p string, l int) string

PadRight pads a string on the right

func RemoveSpecialCharacters added in v1.3.4

func RemoveSpecialCharacters(s string) string

func RemoveSpecialChars

func RemoveSpecialChars(in string) string

RemoveSpecialChars removes special characters from a string and replaces them with a dash

func ReplaceWildcard

func ReplaceWildcard(orig string, replaceThis string, withThis string) string

ReplaceWildcard replaces a wildcard {{wildcard}} with a given string

func SBracket

func SBracket(s string) string

SBracket wraps the string in square brackets - []

func SChevrons

func SChevrons(s string) string

SChevrons wraps the string in single chevrons - <>

func SCurlies

func SCurlies(s string) string

SCurlies wraps the string in single curlies - {}

func SParentheses

func SParentheses(s string) string

SParentheses wraps the string in single Parentheses - ()

func SQuote

func SQuote(s string) string

SQuote wraps the string in single quotes - ”

func StrArrayToString

func StrArrayToString(inArray []string) string

StrArrayToString converst a string array into a string

func StrArrayToStringWithSep

func StrArrayToStringWithSep(inArray []string, inSep string) string

StrArrayToStringWithSep converts a string array to a string using a given separator

Types

This section is empty.

Jump to

Keyboard shortcuts

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