ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - ozgio/strutil: String utilities for Go
String utilities for Go. Contribute to ozgio/strutil development by creating an account on GitHub.
Visit Site

GitHub - ozgio/strutil: String utilities for Go

GitHub - ozgio/strutil: String utilities for Go

String Utilities for Go

GoReportCard GoDocs

"strutil" provides string functions for go applications.

For documentation with examples see GoDoc

Functions

Align (Docs)

Aligns the text to the specified side

strutil.Align("lorem ipsum", strutil.Right, 20) //->"        lorem ipsum" 

AlignCenter (Docs)

Aligns the text to the center

strutil.AlignCenter("lorem\nipsum", 10) //->"  lorem   \n  ipsum   " 

AlignLeft (Docs)

Aligns the text to the left

strutil.AlignLeft("  lorem   \n  ipsum   ") //->"lorem   \nipsum   " 

AlignRight (Docs)

Aligns the text to the right

strutil.AlignRight("lorem\nipsum", 10) //-> "     lorem\n     ipsum" 

CountWords (Docs)

Counts the words

strutil.CountWords("Lorem ipsum, dolor sit amet") //-> "5"

DrawBox (Docs)

Draws a frame around the string with default character set

strutil.DrawBox("Hello World", 20, strutil.Center)
//┌──────────────────┐
//│   Hello World    │
//└──────────────────┘

DrawCustomBox (Docs)

Draws a frame around the string with custom character set

strutil.DrawCustomBox("Hello World", 20, strutil.Center, strutil.SimpleBox9Slice(), "\n")
//┌──────────────────┐
//│   Hello World    │
//└──────────────────┘

ExpandTabs (Docs)

Converts tabs to the spaces

strutil.ExpandTabs("\tlorem\n\tipsum\n", 2) //-> "  lorem\n  ipsum\n"

Indent (Docs)

Indents every line

strutil.Indent("lorem\nipsum", "> ") //-> "> lorem\n> ipsum"

IsASCII (Docs)

Checks if all the characters in string are in standard ASCII table

strutil.IsASCII("lorem\nipsum") //-> true

Len (Docs)

Alias of utf8.RuneCountInString which returns the number of runes in string

strutil.Len("böt") //-> "3"

MapLines (Docs)

Runs function fn on every line of the string

strutil.MapLines("   lorem      \n    ipsum      ", strings.TrimSpace) //-> "lorem\nipsum"

OSNewLine (Docs)

OSNewLine returns operating systems default new line character

strutil.OSNewLine() //-> "\n"

Pad (Docs)

Left and right pads the string

strutil.Pad("lorem", 11, "->", "<-") //-> "->->lorem<-<-"

PadLeft (Docs)

Left pads the string

strutil.PadLeft("lorem", 9, "->") //-> "->->lorem"

PadRight (Docs)

Right pads the string

strutil.PadRight("lorem", 9, "<-") //-> "lorem<-<-"

Random (Docs)

Creates a random string from a character set

strutil.Random("abcdefghi", 10) //-> "aciafbeafg"

RemoveAccents (Docs)

Convert accented letters to ascii counterparts

strutil.RemoveAccents("résumé") //-> "resume"

ReplaceAllToOne (Docs)

Replace all substrings in the text with the specified string

strutil.ReplaceAllToOne("lorem ipsum", []string{"o","e","i","u"}, ".") //-> "l.r.m .ps.m"

Reverse (Docs)

Reverses the string

strutil.Reverse("lorem") //-> "merol"

Splice (Docs)

Replaces a part of the string

strutil.Splice("lorem", "-x-", 2, 3) //-> "lo-x-em"

SplitAndMap (Docs)

Splits the string and runs the function fn on every part

strutil.MapLines("lorem-ipsum-dolor", "-",  strutil.Reverse) //-> "merol\nmuspi\nrolod"

Slugify (Docs)

Converts the string to a slug

strutil.Slugify("Lorem ipsum, dolör") //-> "lorem-ipsum-dolor"

SlugifySpecial (Docs)

Converts the string to a slug with custom delimiter.

strutil.SlugifySpecial("Lorem ipsum, dolör", "_") //-> "lorem_ipsum_dolor"

SplitCamelCase (Docs)

Splits the words in a camelCase string

strutil.SplitCamelCase("loremIpsum") //-> []string{"lorem", "Ipsum"}

Substring (Docs)

Gets a part of the string without panics

strutil.SafeSubstring("lorem", 0, 1) //-> "l"

MustSubstring (Docs)

Gets a part of the string

strutil.Substring("lorem", 0, 1) //-> "l"

Summary (Docs)

Cuts the string to the specified length

strutil.Summary("Lorem ipsum dolor sit amet",  10, "...") //-> "lorem ipsum..."

Tile (Docs)

Repeats the pattern until the result reaches the 'length'

strutil.Tile("-৹", 4) //-> "-৹-৹"

ToSnakeCase (Docs)

Converts the string to snake_case

strutil.ToSnakeCase("Snake Case") //-> "snake_case"

ToCamelCase (Docs)

Converts the string to camelCase

strutil.ToCamelCase("Camel Case") //-> "camelCase"

Words (Docs)

Returns the words inside the text

strutil.Words("Lorem ipsum, dolor sit amet") //-> []string{"Lorem", "ipsum", "dolor", "sit", "amet"}

WordWrap (Docs)

Wraps the lines in the text

strutil.WordWrap("Lorem ipsum dolor sit amet", 15, false) //-> "Lorem ipsum\ndolor sit amet"

Install

Prequsities:

  • Go 1.10+

Install with

go get github.com/ozgio/strutil

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory