📚 xstrings - Awesome Go Library for Miscellaneous

Go Gopher mascot for xstrings

Collection of useful string functions ported from other languages.

🏷️ Miscellaneous
📂 Libraries for working with strings.
1,393 stars
View on GitHub 🔗

Detailed Description of xstrings

xstrings

Build Status Go Doc Go Report Coverage Status

Go package xstrings is a collection of string functions, which are widely used in other languages but absent in Go package strings.

All functions are well tested and carefully tuned for performance.

Propose a new function

Please review contributing guideline and create new issue to state why it should be included.

Install

Use go get to install this library.

go get github.com/huandu/xstrings

API document

See GoDoc for full document.

Function list

Go functions have a unique naming style. One, who has experience in other language but new in Go, may have difficulties to find out right string function to use.

Here is a list of functions in strings and xstrings with enough extra information about how to map these functions to their friends in other languages. Hope this list could be helpful for fresh gophers.

Package xstrings functions

Keep this table sorted by Function in ascending order.

FunctionFriends#
Centerstr.center in Python; String#center in Ruby#30
CountString#count in Ruby#16
DeleteString#delete in Ruby#17
ExpandTabsstr.expandtabs in Python#27
FirstRuneToLowerlcfirst in PHP or Perl#15
FirstRuneToUpperString#capitalize in Ruby; ucfirst in PHP or Perl#15
InsertString#insert in Ruby#18
LastPartitionstr.rpartition in Python; String#rpartition in Ruby#19
LeftJustifystr.ljust in Python; String#ljust in Ruby#28
Lenmb_strlen in PHP#23
Partitionstr.partition in Python; String#partition in Ruby#10
ReverseString#reverse in Ruby; strrev in PHP; reverse in Perl#7
RightJustifystr.rjust in Python; String#rjust in Ruby#29
RuneWidth-#27
ScrubString#scrub in Ruby#20
Shufflestr_shuffle in PHP#13
ShuffleSourcestr_shuffle in PHP#13
Slicemb_substr in PHP#9
SqueezeString#squeeze in Ruby#11
SuccessorString#succ or String#next in Ruby#22
SwapCasestr.swapcase in Python; String#swapcase in Ruby#12
ToCamelCaseString#camelize in RoR#1
ToKebab-#41
ToPascalCase-#1
ToSnakeCaseString#underscore in RoR#1
Translatestr.translate in Python; String#tr in Ruby; strtr in PHP; tr/// in Perl#21
Widthmb_strwidth in PHP#26
WordCountstr_word_count in PHP#14
WordSplit-#14

Package strings functions

Keep this table sorted by Function in ascending order.

FunctionFriends
ContainsString#include? in Ruby
ContainsAny-
ContainsRune-
Countstr.count in Python; substr_count in PHP
EqualFoldstricmp in PHP; String#casecmp in Ruby
Fieldsstr.split in Python; split in Perl; String#split in Ruby
FieldsFunc-
HasPrefixstr.startswith in Python; String#start_with? in Ruby
HasSuffixstr.endswith in Python; String#end_with? in Ruby
Indexstr.index in Python; String#index in Ruby; strpos in PHP; index in Perl
IndexAny-
IndexByte-
IndexFunc-
IndexRune-
Joinstr.join in Python; Array#join in Ruby; implode in PHP; join in Perl
LastIndexstr.rindex in Python; String#rindex; strrpos in PHP; rindex in Perl
LastIndexAny-
LastIndexFunc-
MapString#each_codepoint in Ruby
Repeatoperator * in Python and Ruby; str_repeat in PHP
Replacestr.replace in Python; String#sub in Ruby; str_replace in PHP
Splitstr.split in Python; String#split in Ruby; explode in PHP; split in Perl
SplitAfter-
SplitAfterN-
SplitNstr.split in Python; String#split in Ruby; explode in PHP; split in Perl
Titlestr.title in Python
ToLowerstr.lower in Python; String#downcase in Ruby; strtolower in PHP; lc in Perl
ToLowerSpecial-
ToTitle-
ToTitleSpecial-
ToUpperstr.upper in Python; String#upcase in Ruby; strtoupper in PHP; uc in Perl
ToUpperSpecial-
Trimstr.strip in Python; String#strip in Ruby; trim in PHP
TrimFunc-
TrimLeftstr.lstrip in Python; String#lstrip in Ruby; ltrim in PHP
TrimLeftFunc-
TrimPrefix-
TrimRightstr.rstrip in Python; String#rstrip in Ruby; rtrim in PHP
TrimRightFunc-
TrimSpacestr.strip in Python; String#strip in Ruby; trim in PHP
TrimSuffixString#chomp in Ruby; chomp in Perl

License

This library is licensed under MIT license. See LICENSE for details.