You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 35 Next »
gstr提供了强大便捷的文本处理组件,组件内置了90+个常用的字符串处理方法。
gstr
90+
迄今为止功能最全面的Golang文本处理组件。虽然在源码中英文注释比较全面,但是缺乏中文文档介绍以及使用示例,期望能在框架官网中增加中文介绍以及示例。
Golang
使用方式:
import "github.com/gogf/gf/text/gstr"
接口文档:
https://godoc.org/github.com/gogf/gf/text/gstr
示例:
func ExampleAddSlashes() { var str string str = `'aa'"bb"cc\r\n\d\t` rsStr := gstr.AddSlashes(str) fmt.Println(rsStr) // Output: // \'aa\'\"bb\"cc\\r\\n\\d\\t }
示例: `goframe_is very nice.to-use` 字符串中的下划线,空格,点,中横杠都可以作为驼峰的分割点。
func ExampleCaseCamel() { var str string str = `goframe_is very nice.to-use` rsStr := gstr.CaseCamel(str) fmt.Println(rsStr) // Output: // GoframeIsVeryNiceToUse }
func ExampleCaseCamelLower() { var str string str = `goframe_is very nice.to-use` rsStr := gstr.CaseCamelLower(str) fmt.Println(rsStr) // Output: // goframeIsVeryNiceToUse }
示例: del参数为int8类型的35,就是字符 # (井号)
func ExampleCaseDelimited() { var str string var del uint8 str = `goframe_is_very-nice.to-use` del = 35 rsStr := gstr.CaseDelimited(str,del) fmt.Println(rsStr) // Output: // goframe#is#very#nice#to#use }
func ExampleCaseDelimitedScreaming() { var str string var del uint8 var screaming bool str = `goframe_is Very Nice.to-use` del = 35 screaming = true rsStr := gstr.CaseDelimitedScreaming(str,del,screaming) fmt.Println(rsStr) // Output: // GOFRAME#IS#VERY#NICE#TO#USE }
func ExampleCaseKebab() { var str string str = `goframe_is Very Nice.to-use` rsStr := gstr.CaseKebab(str) fmt.Println(rsStr) // Output: // goframe-is-very-nice-to-use }
func ExampleCaseKebabScreaming() { var str string str = `goframe_is Very Nice.to-use` rsStr := gstr.CaseKebabScreaming(str) fmt.Println(rsStr) // Output: // GOFRAME-IS-VERY-NICE-TO-USE }
func ExampleCaseSnake() { var str string str = `goframe_is Very Nice.to-use` rsStr := gstr.CaseSnake(str) fmt.Println(rsStr) // Output: // goframe_is_very_nice_to_use }
func ExampleCaseSnakeFirstUpper() { var str string str = `GoframeIsVeryNiceToUse` rsStr := gstr.CaseSnakeFirstUpper(str) fmt.Println(rsStr) // Output: // goframe_is_very_nice_to_use }