xstr 是一个字符串函数集合, 这些函数在其他语言中被广泛使用但是在strings中却没有.
使用 go get 安装
go get -u github.com/g-lib/xstr
| 函数 | Friends | # |
|---|---|---|
| Center | str.center in Python; String#center in Ruby |
|
| Count | String#count in Ruby |
|
| Delete | String#delete in Ruby |
|
| ExpandTabs | str.expandtabs in Python |
|
| FirstRuneToLower | lcfirst in PHP or Perl |
|
| FirstRuneToUpper | String#capitalize in Ruby; ucfirst in PHP or Perl |
|
| Insert | String#insert in Ruby |
|
| LastPartition | str.rpartition in Python; String#rpartition in Ruby |
|
| LeftJustify | str.ljust in Python; String#ljust in Ruby |
|
| Len | mb_strlen in PHP |
|
| Partition | str.partition in Python; String#partition in Ruby |
|
| Reverse | String#reverse in Ruby; strrev in PHP; reverse in Perl |
|
| RightJustify | str.rjust in Python; String#rjust in Ruby |
|
| RuneWidth | - | |
| Scrub | String#scrub in Ruby |
|
| Shuffle | str_shuffle in PHP |
|
| ShuffleSource | str_shuffle in PHP |
|
| Slice | mb_substr in PHP |
|
| Squeeze | String#squeeze in Ruby |
|
| Successor | String#succ or String#next in Ruby |
|
| SwapCase | str.swapcase in Python; String#swapcase in Ruby |
|
| ToCamelCase | String#camelize in RoR |
|
| ToKebab | - | |
| ToSnakeCase | String#underscore in RoR |
|
| Translate | str.translate in Python; String#tr in Ruby; strtr in PHP; tr/// in Perl |
|
| Width | mb_strwidth in PHP |
|
| WordCount | str_word_count in PHP |
|
| WordSplit | - | |
| Contains | String#include? in Ruby |
|
| ContainsAny | - | |
| ContainsRune | - | |
| Count | str.count in Python; substr_count in PHP |
|
| EqualFold | stricmp in PHP; String#casecmp in Ruby |
|
| Fields | str.split in Python; split in Perl; String#split in Ruby |
|
| FieldsFunc | - | |
| HasPrefix | str.startswith in Python; String#start_with? in Ruby |
|
| HasSuffix | str.endswith in Python; String#end_with? in Ruby |
|
| Index | str.index in Python; String#index in Ruby; strpos in PHP; index in Perl |
|
| IndexAny | - | |
| IndexByte | - | |
| IndexFunc | - | |
| IndexRune | - | |
| Join | str.join in Python; Array#join in Ruby; implode in PHP; join in Perl |
|
| LastIndex | str.rindex in Python; String#rindex; strrpos in PHP; rindex in Perl |
|
| LastIndexAny | - | |
| LastIndexFunc | - | |
| Map | String#each_codepoint in Ruby |
|
| Repeat | operator * in Python and Ruby; str_repeat in PHP |
|
| Replace | str.replace in Python; String#sub in Ruby; str_replace in PHP |
|
| Split | str.split in Python; String#split in Ruby; explode in PHP; split in Perl |
|
| SplitAfter | - | |
| SplitAfterN | - | |
| SplitN | str.split in Python; String#split in Ruby; explode in PHP; split in Perl |
|
| Title | str.title in Python |
|
| ToLower | str.lower in Python; String#downcase in Ruby; strtolower in PHP; lc in Perl |
|
| ToLowerSpecial | - | |
| ToTitle | - | |
| ToTitleSpecial | - | |
| ToUpper | str.upper in Python; String#upcase in Ruby; strtoupper in PHP; uc in Perl |
|
| ToUpperSpecial | - | |
| Trim | str.strip in Python; String#strip in Ruby; trim in PHP |
|
| TrimFunc | - | |
| TrimLeft | str.lstrip in Python; String#lstrip in Ruby; ltrim in PHP |
|
| TrimLeftFunc | - | |
| TrimPrefix | - | |
| TrimRight | str.rstrip in Python; String#rstrip in Ruby; rtrim in PHP |
|
| TrimRightFunc | - | |
| TrimSpace | str.strip in Python; String#strip in Ruby; trim in PHP |
|
| TrimSuffix | String#chomp in Ruby; chomp in Perl |
本库遵循MIT协议
原始代码源自 xstrings