strings

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package strings provides utility functions for string manipulation and processing.

This package offers a collection of helper functions for common string operations including transformations, validations, and conversions that complement the standard library's strings package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compose added in v0.5.0

func Compose(s string, funcs ...func(string) string) string

Compose chains multiple functions to a string.

Example
package main

import (
	"fmt"
	"strings"

	stringsx "github.com/foomo/go/strings"
)

func main() {
	result := stringsx.Compose("HELLO", strings.ToLower, stringsx.FirstToUpper)
	fmt.Println(result)
}
Output:
Hello

func FirstToLower added in v0.5.0

func FirstToLower(s string) string

FirstToLower converts the first character of a string to lowercase.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.FirstToLower("Hello")
	fmt.Println(result)
}
Output:
hello

func FirstToUpper added in v0.5.0

func FirstToUpper(s string) string

FirstToUpper converts the first character of a string to uppercase.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.FirstToUpper("hello")
	fmt.Println(result)
}
Output:
Hello

func HasAnyPrefix added in v0.8.0

func HasAnyPrefix(s string, prefixes ...string) bool

HasAnyPrefix checks if the given string has any of the provided prefixes and returns true if so.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	fmt.Println(strings.HasAnyPrefix("foobar", "foo", "baz"))
}
Output:
true

func HasAnySuffix added in v0.8.0

func HasAnySuffix(s string, suffixes ...string) bool

HasAnySuffix checks if the given string has any of the provided suffixes and returns true if so.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	fmt.Println(strings.HasAnySuffix("foobar", "bar", "baz"))
}
Output:
true

func IsAlpha added in v0.8.0

func IsAlpha(s string) bool

IsAlpha checks if the given string contains only alphabetic characters and returns true if it is, otherwise returns false.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	fmt.Println(strings.IsAlpha("abc"))
}
Output:
true

func IsAlphanumeric added in v0.8.0

func IsAlphanumeric(s string) bool

IsAlphanumeric checks if the given string is alphanumeric and returns true if it is, otherwise returns false.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	fmt.Println(strings.IsAlphanumeric("abc1"))
}
Output:
true

func IsAnyBlank added in v0.8.0

func IsAnyBlank(strings ...string) bool

IsAnyBlank checks if any of the provided strings in the variadic argument is blank and returns true if so.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	fmt.Println(strings.IsAnyBlank("a", " "))
}
Output:
true

func IsAnyEmpty added in v0.8.0

func IsAnyEmpty(s ...string) bool

IsAnyEmpty checks if any of the provided strings in the variadic argument is empty and returns true if so.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	fmt.Println(strings.IsAnyEmpty("a", ""))
}
Output:
true

func IsBlank added in v0.8.0

func IsBlank(s string) bool

IsBlank checks if the given string is blank (contains only whitespace characters) and returns true if it is, otherwise returns false.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	fmt.Println(strings.IsBlank(" \t"))
}
Output:
true

func IsEmpty added in v0.8.0

func IsEmpty(s string) bool

IsEmpty checks if the given string is empty and returns true if it is, otherwise returns false.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	fmt.Println(strings.IsEmpty(""))
}
Output:
true

func IsNumeric added in v0.8.0

func IsNumeric(s string) bool

IsNumeric checks if the given string is numeric and returns true if it is, otherwise returns false.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	fmt.Println(strings.IsNumeric("123"))
}
Output:
true

func IsNumerical added in v0.8.0

func IsNumerical(s string) bool

IsNumerical checks if the given string is numerical and returns true if it is, otherwise returns false.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	fmt.Println(strings.IsNumerical("12.3"))
}
Output:
true

func PadLeft added in v0.2.0

func PadLeft(s string, n int) string

PadLeft prepends spaces to the left of the input string s until it reaches the specified rune length n.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.PadLeft("hello", 10)
	fmt.Printf("'%s'", result)
}
Output:
'     hello'

func PadRight added in v0.2.0

func PadRight(s string, n int) string

PadRight appends spaces to the right of the input string s until it reaches the specified rune length n.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.PadRight("hello", 10)
	fmt.Printf("'%s'", result)
}
Output:
'hello     '

func RemoveAll added in v0.2.0

func RemoveAll(s string, substrings ...string) string

RemoveAll removes all occurrences of each substring from s in a single pass.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.RemoveAll("hello world", "o", "l")
	fmt.Println(result)
}
Output:
he wrd

func ToCamel

func ToCamel(s string) string

ToCamel converts a string to CamelCase format by removing delimiters and capitalizing appropriate letters.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.ToCamel("hello_world_example")
	fmt.Println(result)
}
Output:
HelloWorldExample

func ToDelimited

func ToDelimited(s string, delimiter uint8) string

ToDelimited converts a string to delimited.snake.case

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.ToDelimited("HelloWorldExample", '.')
	fmt.Println(result)
}
Output:
hello.world.example

func ToKebab

func ToKebab(s string) string

ToKebab converts a string to kebab-case format using hyphens as delimiters.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.ToKebab("HelloWorldExample")
	fmt.Println(result)
}
Output:
hello-world-example

func ToLowerCamel

func ToLowerCamel(s string) string

ToLowerCamel converts a string to lowerCamelCase format by removing delimiters and capitalizing appropriate letters.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.ToLowerCamel("hello_world_example")
	fmt.Println(result)
}
Output:
helloWorldExample

func ToScreamingDelimited

func ToScreamingDelimited(s string, delimiter uint8, ignore string, screaming bool) string

ToScreamingDelimited converts a string to SCREAMING_DELIMITED_CASE

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.ToScreamingDelimited("HelloWorldExample", '.', "", true)
	fmt.Println(result)
}
Output:
HELLO.WORLD.EXAMPLE

func ToScreamingKebab

func ToScreamingKebab(s string) string

ToScreamingKebab converts a string to SCREAMING-KEBAB-CASE format using hyphens as delimiters.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.ToScreamingKebab("HelloWorldExample")
	fmt.Println(result)
}
Output:
HELLO-WORLD-EXAMPLE

func ToScreamingSnake

func ToScreamingSnake(s string) string

ToScreamingSnake converts a given string to SCREAMING_SNAKE_CASE format using underscores as delimiters.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.ToScreamingSnake("HelloWorldExample")
	fmt.Println(result)
}
Output:
HELLO_WORLD_EXAMPLE

func ToSnake

func ToSnake(s string) string

ToSnake converts a given string to snake_case format using underscores as delimiters.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/strings"
)

func main() {
	result := strings.ToSnake("HelloWorldExample")
	fmt.Println(result)
}
Output:
hello_world_example

func ToSnakeWithIgnore

func ToSnakeWithIgnore(s string, ignore string) string

ToSnakeWithIgnore converts the input string `s` to snake_case format while ignoring characters specified in `ignore`.

Types

This section is empty.

Jump to

Keyboard shortcuts

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