Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

Function
Friends
#

str.center in Python; String#center in Ruby

String#count in Ruby

String#delete in Ruby

str.expandtabs in Python

lcfirst in PHP or Perl

String#capitalize in Ruby; ucfirst in PHP or Perl

String#insert in Ruby

str.rpartition in Python; String#rpartition in Ruby

str.ljust in Python; String#ljust in Ruby

mb_strlen in PHP

str.partition in Python; String#partition in Ruby

String#reverse in Ruby; strrev in PHP; reverse in Perl

str.rjust in Python; String#rjust in Ruby

String#scrub in Ruby

str_shuffle in PHP

str_shuffle in PHP

mb_substr in PHP

String#squeeze in Ruby

String#succ or String#next in Ruby

str.swapcase in Python; String#swapcase in Ruby

String#camelize in RoR

String#underscore in RoR

str.translate in Python; String#tr in Ruby; strtr in PHP; tr/// in Perl

mb_strwidth in PHP

str_word_count in PHP

Package strings functions

Keep this table sorted by Function in ascending order.

Function
Friends

String#include? in Ruby

str.count in Python; substr_count in PHP

stricmp in PHP; String#casecmp in Ruby

str.split in Python; split in Perl; String#split in Ruby

str.startswith in Python; String#start_with? in Ruby

str.endswith in Python; String#end_with? in Ruby

str.index in Python; String#index in Ruby; strpos in PHP; index in Perl

str.join in Python; Array#join in Ruby; implode in PHP; join in Perl

str.rindex in Python; String#rindex; strrpos in PHP; rindex in Perl

String#each_codepoint in Ruby

operator * in Python and Ruby; str_repeat in PHP

str.replace in Python; String#sub in Ruby; str_replace in PHP

str.split in Python; String#split in Ruby; explode in PHP; split in Perl

str.split in Python; String#split in Ruby; explode in PHP; split in Perl

str.title in Python

str.lower in Python; String#downcase in Ruby; strtolower in PHP; lc in Perl

str.upper in Python; String#upcase in Ruby; strtoupper in PHP; uc in Perl

str.strip in Python; String#strip in Ruby; trim in PHP

str.lstrip in Python; String#lstrip in Ruby; ltrim in PHP

str.rstrip in Python; String#rstrip in Ruby; rtrim in PHP

str.strip in Python; String#strip in Ruby; trim in PHP

String#chomp in Ruby; chomp in Perl

License

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

Last updated

Was this helpful?