SkillAgentSearch skills...

Stringy

Convert string to camel case, snake case, kebab case / slugify, custom delimiter, pad string, tease string and many other functionalities with help of by Stringy package.

Install / Use

/learn @gobeam/Stringy

README

Golang String manipulation helper package

Workflow [![Build][Build-Status-Image]][Build-Status-Url] Go Report Card [![GoDoc][godoc-image]][godoc-url] Coverage Status

Convert string to camel case, snake case, kebab case / slugify, custom delimiter, pad string, tease string and many other functionality with help of by Stringy package. You can convert camelcase to snakecase or kebabcase, or snakecase to camelcase and kebabcase and vice versa. This package was inspired from PHP danielstjules/Stringy.

<table> <tr> <td><a href="#acronym-string">Acronym</a></td> <td><a href="#betweenstart-end-string-stringmanipulation">Between</a></td> <td><a href="#boolean-bool">Boolean</a></td> </tr> <tr> <td><a href="#camelcaserule-string-string">CamelCase</a></td> <td><a href="#containsallcheck-string-bool">ContainsAll</a></td> <td><a href="#containssubstring-string-bool">Contains</a></td> </tr> <tr> <td><a href="#delimiteddelimiter-string-rule-string-stringmanipulation">Delimited</a></td> <td><a href="#firstlength-int-string">First</a></td> <td><a href="#get-string">Get</a></td> </tr> <tr> <td><a href="#isempty-bool">IsEmpty</a></td> <td><a href="#kebabcaserule-string-stringmanipulation">KebabCase</a></td> <td><a href="#lastlength-int-string">Last</a></td> </tr> <tr> <td><a href="#lcfirst-string">LcFirst</a></td> <td><a href="#lines-string">Lines</a></td> <td><a href="#padlength-int-with-padtype-string-string">Pad</a></td> </tr> <tr> <td><a href="#pascalcaserule-string-string">PascalCase</a></td> <td><a href="#prefixstring-string">Prefix</a></td> <td><a href="#removespecialcharacter-string">RemoveSpecialCharacter</a></td> </tr> <tr> <td><a href="#replaceallsearch-replace-string-stringmanipulation">ReplaceAll</a></td> <td><a href="#replacefirstsearch-replace-string-string">ReplaceFirst</a></td> <td><a href="#replacelastsearch-replace-string-string">ReplaceLast</a></td> </tr> <tr> <td><a href="#reverse-string">Reverse</a></td> <td><a href="#sentencecaserule-string-stringmanipulation">SentenceCase</a></td> <td><a href="#shuffle-string">Shuffle</a></td> </tr> <tr> <td><a href="#slugifywithcountcount-int-stringmanipulation">SlugifyWithCount</a></td> <td><a href="#snakecaserule-string-stringmanipulation">SnakeCase</a></td> <td><a href="#substringstart-end-int-stringmanipulation">Substring</a></td> </tr> <tr> <td><a href="#suffixstring-string">Suffix</a></td> <td><a href="#surroundwith-string-string">Surround</a></td> <td><a href="#teaselength-int-indicator-string-string">Tease</a></td> </tr> <tr> <td><a href="#title-string">Title</a></td> <td><a href="#tolower-string">ToLower</a></td> <td><a href="#toupper-string">ToUpper</a></td> </tr> <tr> <td><a href="#trimcutset-string-stringmanipulation">Trim</a></td> <td><a href="#truncatewordscount-int-suffix-string-stringmanipulation">TruncateWords</a></td> <td><a href="#ucfirst-string">UcFirst</a></td> </tr> <tr> <td><a href="#wordcount-int">WordCount</a></td> <td><a href="#substringstart-end-int-stringmanipulation">Substring</a></td> <td></td> </tr> </table>

Why?

Golang has very rich strings core package despite some extra helper function are not available and this stringy package is here to fill that void. Plus there are other some packages in golang, that have same functionality but for some extreme cases they fail to provide correct output. This package cross flexibility is it's main advantage. You can convert to camelcase to snakecase or kebabcase or vice versa.

package main

import (
	"fmt"
	"github.com/gobeam/stringy"
    )

func main() {
 str := stringy.New("hello__man how-Are you??")
 result := str.CamelCase("?", "")
 fmt.Println(result) // HelloManHowAreYou

 snakeStr := str.SnakeCase("?", "")
 fmt.Println(snakeStr.ToLower()) // hello_man_how_are_you

 kebabStr := str.KebabCase("?", "")
 fmt.Println(kebabStr.ToUpper()) // HELLO-MAN-HOW-ARE-YOU
}

Installation

$ go get -u -v github.com/gobeam/stringy

or with dep

$ dep ensure -add github.com/gobeam/stringy

Functions

Between(start, end string) StringManipulation

Between takes two string params start and end which and returns value which is in middle of start and end part of input. You can chain to upper which with make result all uppercase or ToLower which will make result all lower case or Get which will return result as it is.

  strBetween := stringy.New("HelloMyName")
  fmt.Println(strBetween.Between("hello", "name").ToUpper()) // MY

Boolean() bool

Boolean func returns boolean value of string value like on, off, 0, 1, yes, no returns boolean value of string input. You can chain this function on other function which returns implemented StringManipulation interface.

  boolString := stringy.New("off")
  fmt.Println(boolString.Boolean()) // false

CamelCase(rule ...string) string

CamelCase is variadic function which takes one Param rule i.e slice of strings and it returns input type string in camel case form and rule helps to omit character you want to omit from string. By default special characters like "_", "-","."," " are treated like word separator and treated accordingly by default and you dont have to worry about it.

  camelCase := stringy.New("ThisIsOne___messed up string. Can we Really camel-case It ?##")
  fmt.Println(camelCase.CamelCase("?", "", "#", "")) // thisIsOneMessedUpStringCanWeReallyCamelCaseIt

look how it omitted ?## from string. If you dont want to omit anything and since it returns plain strings and you cant actually cap all or lower case all camelcase string its not required.

  camelCase := stringy.New("ThisIsOne___messed up string. Can we Really camel-case It ?##")
  fmt.Println(camelCase.CamelCase()) // thisIsOneMessedUpStringCanWeReallyCamelCaseIt?##

Contains(substring string) bool

Contains checks if the string contains the specified substring and returns a boolean value. This is a wrapper around Go's standard strings.Contains function that fits into the Stringy interface.

  str := stringy.New("Hello World")
  fmt.Println(str.Contains("World")) // true
  fmt.Println(str.Contains("Universe")) // false

ContainsAll(check ...string) bool

ContainsAll is variadic function which takes slice of strings as param and checks if they are present in input and returns boolean value accordingly.

  contains := stringy.New("hello mam how are you??")
  fmt.Println(contains.ContainsAll("mam", "?")) // true

Delimited(delimiter string, rule ...string) StringManipulation

Delimited is variadic function that takes two params delimiter and slice of strings named rule. It joins the string by passed delimeter. Rule param helps to omit character you want to omit from string. By default special characters like "_", "-","."," " are treated like word separator and treated accordingly by default and you dont have to worry about it. If you don't want to omit any character pass empty string.

  delimiterString := stringy.New("ThisIsOne___messed up string. Can we Really delimeter-case It?")
  fmt.Println(delimiterString.Delimited("?").Get())

You can chain to upper which with make result all uppercase or ToLower which will make result all lower case or Get which will return result as it is.

First(length int) string

First returns first n characters from provided input. It removes all spaces in string before doing so.

  fcn := stringy.New("4111 1111 1111 1111")
  first := fcn.First(4)
  fmt.Println(first) // 4111

Get() string

Get simply returns result and can be chained on function which returns StringManipulation interface view above examples

  getString := stringy.New("hello roshan")
  fmt.Println(getString.Get()) // hello roshan

IsEmpty() bool

IsEmpty checks if the string is empty or contains only whitespace characters. It returns true for empty strings or strings containing only spaces, tabs, or newlines.

  emptyStr := stringy.New("")
  fmt.Println(emptyStr.IsEmpty()) // true
  
  whitespaceStr := stringy.New("   \t\n")
  fmt.Println(whitespaceStr.IsEmpty()) // true
  
  normalStr := stringy.New("Hello")
  fmt.Println(normalStr.IsEmpty()) // false

  emptyStr := stringy.New("")
  fmt.Println(emptyStr.IsEmpty()) // true
  
  whitespaceStr := stringy.New("   \t\n")
  fmt.Println(whitespaceStr.IsEmpty()) // true
  
  normalStr := stringy.New("Hello")
  fmt.Println(normalStr.IsEmpty()) // false


#### KebabCase(rule ...string) StringManipulation

KebabCase/slugify is variadic function that takes one Param slice of strings named rule and it returns passed string in kebab case or slugify form. Rule param helps to omit character you want to omit from string. By default special characters like "_", "-","."," " are treated like word separator and treated accordingly by default and you don't have to worry about it. If you don't want to omit any character pass nothing.

```go
  str := stringy.New("hello__man how-Are you??")
  kebabStr := str.KebabCase("?","")
  fmt.Println(kebabStr.ToUp

Related Skills

View on GitHub
GitHub Stars251
CategoryDevelopment
Updated4mo ago
Forks20

Languages

Go

Security Score

97/100

Audited on Nov 26, 2025

No findings