Help us shape the future of Go! Take the 2026 Go Developer Survey

strext

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2019 License: MIT Imports: 5 Imported by: 1

README

strext 字符串扩展包

GoDoc Build Status codecov Action Status Go Report Card Licence

基本功能

  strext.Recombine("HelloWorld",'_') ==> "hello_world"  
  strext.Recombine("HelloWor_ld",'_') ==> "hello_wor_ld"  
  strext.Recombine("HiHello_World",'_') ==> "hi_hello_world"  

  strext.UnRecombine("hello_world",'_') ==> "HelloWorld"  

  strext.Recombine("IDCom",'_') ==> "id_com"
  strext.Recombine("IDcom",'_') ==> "i_dcom"
  strext.Recombine("nameIDCom",'_') ==> "name_id_com" 
  strext.Recombine("nameIDcom",'_') ==> "name_i_dcom" 

  recode := strext.NewRecode([]string{"ID"})  
  recode.Recombine("IDCom",'_') ==> "id_com"
  recode.Recombine("IDcom",'_') ==> "idcom"  
  recode.Recombine("nameIDCom",'_') ==> "name_id_com"  
  recode.Recombine("nameIDcom",'_') ==> "name_idcom"      

将字符串单数变为复数 或 复数转为单数

@see inflection

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(strs []string, str string) []string

Append appends string to slice with no duplicates. 追加字符串,无重复项

func Bytes2Str

func Bytes2Str(b []byte) string

Bytes2Str Zero-copy convert from byte slice to a string see reflect.SliceHeader and reflect.StringHeader 理论上是 string(byte{"a","b"}) 的20倍速率

func Compare

func Compare(s1, s2 []string) bool

Compare compares two 'string' type slices. It returns true if elements and order are both the same. 比较两个字符串切片,要求元素和顺序都一致才返回true

func CompareU

func CompareU(s1, s2 []string) bool

CompareU compares two 'string' type slices. It returns true if elements are the same, and ignores the order. 比较两个字符串切片,要求元素一致,且忽略顺序,一致返回true

func Contains

func Contains(sl []string, str string) bool

Contains returns true if the string exists in given slice 字符串切片是否含有指定的元素,大小写敏感

func ContainsNocase

func ContainsNocase(sl []string, str string) bool

ContainsNocase returns true if the string exists in given slice, ignore case. 字符串切片是否含有指定的元素,忽略大小写

func Delete

func Delete(s []string, e string) []string

Delete 删除string切片中的,第一个出现的指定元素

func DeleteAll

func DeleteAll(s []string, e string) []string

DeleteAll 删除string切片中的 所有出现的指示元素

func FormatBaseType

func FormatBaseType(val interface{}, args ...int) (s string)

FormatBaseType 格式基本数据类型的字符串,如果非基本数据格式,则采用默认方式fmt.Sprintf("%v", val)格式化 bool, *bool - see strconv.FormatBool int,int8,int16,int32,int64,*int,*int8,*int16,*int32,*int64 - 默认base为10, see strconv.FormatInt uint,uint8,uint16,uint32,uint64,*uint,*uint8,*uint16,*uint32,*uint64 - 默认base为10, see strconv.FormatUint float32,*float32 - 默认fmt('f'),prec(-1),固定bitSize = 32,see strconv.FormatFloat float64,*float64 - 默认 fmt('f'),prec(-1),固定bitSize = 64,see strconv.FormatFloat string - 原字符串 []byte - string other - fmt.Sprintf("%v", v)

func Recombine

func Recombine(str string, sep byte) string

Recombine 转换驼峰字符串为用sep分隔的字符串 example: sep = '_' HelloWorld -> hello_world Hello_World -> hello_world HiHello_World -> hi_hello_world IDCom -> id_com IDcom -> i_dcom nameIDCom -> name_id_com nameIDcom -> name_i_dcom

func Reverse

func Reverse(s string) string

Reverse 反转字符串

func Str2Bytes

func Str2Bytes(str string) []byte

Str2Bytes Convert different types to byte slice using types and functions in unsafe and reflect package(see reflect.SliceHeader and reflect.StringHeader). It has higher performance, but notice that it may be not safe when garbage collection happens.Use it when you need to temporary convert a long string to a byte slice and won't keep it for long time. 理论上与 []byte("string") 速度几乎是一致的

func UnRecombine

func UnRecombine(str string, sep byte) string

UnRecombine 转换sep分隔的字符串为驼峰字符串 example: sep = '_' hello_world -> HelloWorld

Types

type Recode

type Recode struct {
	// contains filtered or unexported fields
}

Recode 重组转换一些特殊的字符

func NewRecode

func NewRecode(initialisms []string) *Recode

NewRecode 创建一个Recode,以initialisms为自定义的Replacer example: API -> Api ID -> id

func (Recode) Recombine

func (this Recode) Recombine(str string, sep byte) string

Recombine 转换驼峰字符串为用sep分隔的字符串,特殊字符由initialisms决定取代 example1: sep = '_' HelloWorld -> hello_world Hello_World -> hello_world HiHello_World -> hi_hello_world example2: sep = '_' initialisms = [ID] IDCom -> id_com IDcom -> idcom nameIDCom -> name_id_com nameIDcom -> name_idcom

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL