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 ¶
- func PadLeft(s string, n int) string
- func PadRight(s string, n int) string
- func RemoveAll(s string, substrings ...string) string
- func ToCamel(s string) string
- func ToDelimited(s string, delimiter uint8) string
- func ToKebab(s string) string
- func ToLowerCamel(s string) string
- func ToScreamingDelimited(s string, delimiter uint8, ignore string, screaming bool) string
- func ToScreamingKebab(s string) string
- func ToScreamingSnake(s string) string
- func ToSnake(s string) string
- func ToSnakeWithIgnore(s string, ignore string) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PadLeft ¶ added in v0.2.0
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
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
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ToSnakeWithIgnore converts the input string `s` to snake_case format while ignoring characters specified in `ignore`.
Types ¶
This section is empty.