huandu/xstrings

GitHub: huandu/xstrings

xstrings 是一个 Go 语言字符串工具库,提供其他主流语言中常见但 Go 标准库 strings 缺失的字符串处理函数。

Stars: 1414 | Forks: 70

# xstrings [![构建状态](https://static.pigsec.cn/wp-content/uploads/repos/cas/2a/2a44ebb2294c01676e19eed14adc6cea930435b1ac09f01b83d80f1ec8c274bf.svg)](https://github.com/huandu/xstrings/actions) [![Go 文档](https://godoc.org/github.com/huandu/xstrings?status.svg)](https://pkg.go.dev/github.com/huandu/xstrings) [![Go 报告](https://goreportcard.com/badge/github.com/huandu/xstrings)](https://goreportcard.com/report/github.com/huandu/xstrings) [![覆盖率状态](https://coveralls.io/repos/github/huandu/xstrings/badge.svg?branch=master)](https://coveralls.io/github/huandu/xstrings?branch=master) Go 包 [xstrings](https://godoc.org/github.com/huandu/xstrings) 是一个字符串函数集合,这些函数在其他语言中被广泛使用,但在 Go 包 [strings](http://golang.org/pkg/strings) 中却不存在。 所有函数都经过了充分测试,并针对性能进行了仔细调优。 ## 提出新函数 ## 安装 使用 `go get` 安装此库。 ``` go get github.com/huandu/xstrings ``` ## API 文档 完整文档请参见 [GoDoc](https://godoc.org/github.com/huandu/xstrings)。 ## 函数列表 Go 函数具有独特的命名风格。有其他语言经验但对 Go 不熟悉的人,可能很难找到需要使用的正确字符串函数。 这里是 [strings](http://golang.org/pkg/strings) 和 [xstrings](https://godoc.org/github.com/huandu/xstrings) 中的函数列表,其中包含了足够多的额外信息,说明了如何将这些函数映射到其他语言中的同类函数。希望这个列表能对初识 Go 的 Gopher 有所帮助。 ### `xstrings` 包函数 _保持此表按 Function 升序排列。_ | Function | Friends | # | | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | --------------------------------------------------- | | [Center](https://godoc.org/github.com/huandu/xstrings#Center) | Python 中的 `str.center`;Ruby 中的 `String#center` | [#30](https://github.com/huandu/xstrings/issues/30) | | [Count](https://godoc.org/github.com/huandu/xstrings#Count) | Ruby 中的 `String#count` | [#16](https://github.com/huandu/xstrings/issues/16) | | [Delete](https://godoc.org/github.com/huandu/xstrings#Delete) | Ruby 中的 `String#delete` | [#17](https://github.com/huandu/xstrings/issues/17) | | [ExpandTabs](https://godoc.org/github.com/huandu/xstrings#ExpandTabs) | Python 中的 `str.expandtabs` | [#27](https://github.com/huandu/xstrings/issues/27) | | [FirstRuneToLower](https://godoc.org/github.com/huandu/xstrings#FirstRuneToLower) | PHP 或 Perl 中的 `lcfirst` | [#15](https://github.com/huandu/xstrings/issues/15) | | [FirstRuneToUpper](https://godoc.org/github.com/huandu/xstrings#FirstRuneToUpper) | Ruby 中的 `String#capitalize`;PHP 或 Perl 中的 `ucfirst` | [#15](https://github.com/huandu/xstrings/issues/15) | | [Insert](https://godoc.org/github.com/huandu/xstrings#Insert) | Ruby 中的 `String#insert` | [#18](https://github.com/huandu/xstrings/issues/18) | | [LastPartition](https://godoc.org/github.com/huandu/xstrings#LastPartition) | Python 中的 `str.rpartition`;Ruby 中的 `String#rpartition` | [#19](https://github.com/huandu/xstrings/issues/19) | | [LeftJustify](https://godoc.org/github.com/huandu/xstrings#LeftJustify) | Python 中的 `str.ljust`;Ruby 中的 `String#ljust` | [#28](https://github.com/huandu/xstrings/issues/28) | | [Len](https://godoc.org/github.com/huandu/xstrings#Len) | PHP 中的 `mb_strlen` | [#23](https://github.com/huandu/xstrings/issues/23) | | [Partition](https://godoc.org/github.com/huandu/xstrings#Partition) | Python 中的 `str.partition`;Ruby 中的 `String#partition` | [#10](https://github.com/huandu/xstrings/issues/10) | | [Reverse](https://godoc.org/github.com/huandu/xstrings#Reverse) | Ruby 中的 `String#reverse`;PHP 中的 `strrev`;Perl 中的 `reverse` | [#7](https://github.com/huandu/xstrings/issues/7) | | [RightJustify](https://godoc.org/github.com/huandu/xstrings#RightJustify) | Python 中的 `str.rjust`;Ruby 中的 `String#rjust` | [#29](https://github.com/huandu/xstrings/issues/29) | | [RuneWidth](https://godoc.org/github.com/huandu/xstrings#RuneWidth) | - | [#27](https://github.com/huandu/xstrings/issues/27) | | [Scrub](https://godoc.org/github.com/huandu/xstrings#Scrub) | Ruby 中的 `String#scrub` | [#20](https://github.com/huandu/xstrings/issues/20) | | [Shuffle](https://godoc.org/github.com/huandu/xstrings#Shuffle) | PHP 中的 `str_shuffle` | [#13](https://github.com/huandu/xstrings/issues/13) | | [ShuffleSource](https://godoc.org/github.com/huandu/xstrings#ShuffleSource) | PHP 中的 `str_shuffle` | [#13](https://github.com/huandu/xstrings/issues/13) | | [Slice](https://godoc.org/github.com/huandu/xstrings#Slice) | PHP 中的 `mb_substr` | [#9](https://github.com/huandu/xstrings/issues/9) | | [Squeeze](https://godoc.org/github.com/huandu/xstrings#Squeeze) | Ruby 中的 `String#squeeze` | [#11](https://github.com/huandu/xstrings/issues/11) | | [Successor](https://godoc.org/github.com/huandu/xstrings#Successor) | Ruby 中的 `String#succ` 或 `String#next` | [#22](https://github.com/huandu/xstrings/issues/22) | | [SwapCase](https://godoc.org/github.com/huandu/xstrings#SwapCase) | Python 中的 `str.swapcase`;Ruby 中的 `String#swapcase` | [#12](https://github.com/huandu/xstrings/issues/12) | | [ToCamelCase](https://godoc.org/github.com/huandu/xstrings#ToCamelCase) | RoR 中的 `String#camelize` | [#1](https://github.com/huandu/xstrings/issues/1) | | [ToKebab](https://godoc.org/github.com/huandu/xstrings#ToKebabCase) | - | [#41](https://github.com/huandu/xstrings/issues/41) | | [ToPascalCase](https://godoc.org/github.com/huandu/xstrings#ToPascalCase) | - | [#1](https://github.com/huandu/xstrings/issues/1) | | [ToSnakeCase](https://godoc.org/github.com/huandu/xstrings#ToSnakeCase) | RoR 中的 `String#underscore` | [#1](https://github.com/huandu/xstrings/issues/1) | | [Translate](https://godoc.org/github.com/huandu/xstrings#Translate) | Python 中的 `str.translate`;Ruby 中的 `String#tr`;PHP 中的 `strtr`;Perl 中的 `tr///` | [#21](https://github.com/huandu/xstrings/issues/21) | | [Width](https://godoc.org/github.com/huandu/xstrings#Width) | PHP 中的 `mb_strwidth` | [#26](https://github.com/huandu/xstrings/issues/26) | | [WordCount](https://godoc.org/github.com/huandu/xstrings#WordCount) | PHP 中的 `str_word_count` | [#14](https://github.com/huandu/xstrings/issues/14) | | [WordSplit](https://godoc.org/github.com/huandu/xstrings#WordSplit) | - | [#14](https://github.com/huandu/xstrings/issues/14) | ### `strings` 包函数 _保持此表按 Function 升序排列。_ | Function | Friends | | --------------------------------------------------------------- | ----------------------------------------------------------------------------------- | | [Contains](http://golang.org/pkg/strings/#Contains) | Ruby 中的 `String#include?` | | [ContainsAny](http://golang.org/pkg/strings/#ContainsAny) | - | | [ContainsRune](http://golang.org/pkg/strings/#ContainsRune) | - | | [Count](http://golang.org/pkg/strings/#Count) | Python 中的 `str.count`;PHP 中的 `substr_count` | | [EqualFold](http://golang.org/pkg/strings/#EqualFold) | PHP 中的 `stricmp`;Ruby 中的 `String#casecmp` | | [Fields](http://golang.org/pkg/strings/#Fields) | Python 中的 `str.split`;Perl 中的 `split`;Ruby 中的 `String#split` | | [FieldsFunc](http://golang.org/pkg/strings/#FieldsFunc) | - | | [HasPrefix](http://golang.org/pkg/strings/#HasPrefix) | Python 中的 `str.startswith`;Ruby 中的 `String#start_with?` | | [HasSuffix](http://golang.org/pkg/strings/#HasSuffix) | Python 中的 `str.endswith`;Ruby 中的 `String#end_with?` | | [Index](http://golang.org/pkg/strings/#Index) | Python 中的 `str.index`;Ruby 中的 `String#index`;PHP 中的 `strpos`;Perl 中的 `index` | | [IndexAny](http://golang.org/pkg/strings/#IndexAny) | - | | [IndexByte](http://golang.org/pkg/strings/#IndexByte) | - | | [IndexFunc](http://golang.org/pkg/strings/#IndexFunc) | - | | [IndexRune](http://golang.org/pkg/strings/#IndexRune) | - | | [Join](http://golang.org/pkg/strings/#Join) | Python 中的 `str.join`;Ruby 中的 `Array#join`;PHP 中的 `implode`;Perl 中的 `join` | | [LastIndex](http://golang.org/pkg/strings/#LastIndex) | Python 中的 `str.rindex`;Ruby 中的 `String#rindex`;PHP 中的 `strrpos`;Perl 中的 `rindex` | | [LastIndexAny](http://golang.org/pkg/strings/#LastIndexAny) | - | | [LastIndexFunc](http://golang.org/pkg/strings/#LastIndexFunc) | - | | [Map](http://golang.org/pkg/strings/#Map) | Ruby 中的 `String#each_codepoint` | | [Repeat](http://golang.org/pkg/strings/#Repeat) | Python 和 Ruby 中的操作符 `*`;PHP 中的 `str_repeat` | | [Replace](http://golang.org/pkg/strings/#Replace) | Python 中的 `str.replace`;Ruby 中的 `String#sub`;PHP 中的 `str_replace` | | [Split](http://golang.org/pkg/strings/#Split) | Python 中的 `str.split`;Ruby 中的 `String#split`;PHP 中的 `explode`;Perl 中的 `split` | | [SplitAfter](http://golang.org/pkg/strings/#SplitAfter) | - | | [SplitAfterN](http://golang.org/pkg/strings/#SplitAfterN) | - | | [SplitN](http://golang.org/pkg/strings/#SplitN) | Python 中的 `str.split`;Ruby 中的 `String#split`;PHP 中的 `explode`;Perl 中的 `split` | | [Title](http://golang.org/pkg/strings/#Title) | Python 中的 `str.title` | | [ToLower](http://golang.org/pkg/strings/#ToLower) | Python 中的 `str.lower`;Ruby 中的 `String#downcase`;PHP 中的 `strtolower`;Perl 中的 `lc` | | [ToLowerSpecial](http://golang.org/pkg/strings/#ToLowerSpecial) | - | | [ToTitle](http://golang.org/pkg/strings/#ToTitle) | - | | [ToTitleSpecial](http://golang.org/pkg/strings/#ToTitleSpecial) | - | | [ToUpper](http://golang.org/pkg/strings/#ToUpper) | Python 中的 `str.upper`;Ruby 中的 `String#upcase`;PHP 中的 `strtoupper`;Perl 中的 `uc` | | [ToUpperSpecial](http://golang.org/pkg/strings/#ToUpperSpecial) | - | | [Trim](http://golang.org/pkg/strings/#Trim) | Python 中的 `str.strip`;Ruby 中的 `String#strip`;PHP 中的 `trim` | | [TrimFunc](http://golang.org/pkg/strings/#TrimFunc) | - | | [TrimLeft](http://golang.org/pkg/strings/#TrimLeft) | Python 中的 `str.lstrip`;Ruby 中的 `String#lstrip`;PHP 中的 `ltrim` | | [TrimLeftFunc](http://golang.org/pkg/strings/#TrimLeftFunc) | - | | [TrimPrefix](http://golang.org/pkg/strings/#TrimPrefix) | - | | [TrimRight](http://golang.org/pkg/strings/#TrimRight) | Python 中的 `str.rstrip`;Ruby 中的 `String#rstrip`;PHP 中的 `rtrim` | | [TrimRightFunc](http://golang.org/pkg/strings/#TrimRightFunc) | - | | [TrimSpace](http://golang.org/pkg/strings/#TrimSpace) | Python 中的 `str.strip`;Ruby 中的 `String#strip`;PHP 中的 `trim` | | [TrimSuffix](http://golang.org/pkg/strings/#TrimSuffix) | Ruby 中的 `String#chomp`;Perl 中的 `chomp` | ## 许可证 该库基于 MIT 许可证授权。详情请参见 LICENSE。
标签:EVTX分析, 日志审计