新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)GoFrame教程:GoFramegstr-命名轉(zhuǎn)換
CaseCamel

- 說明:?
CaseCamel?將字符串轉(zhuǎn)換為大駝峰形式(首字母大寫)。 - 格式:
CaseCamel(s string) string- 示例:
func ExampleCaseCamel() {
var (
str = `hello world`
result = gstr.CaseCamel(str)
)
fmt.Println(result)
// Output:
// HelloWorld
}CaseCamelLower
- 說明:?
CaseCamelLower?將字符串轉(zhuǎn)換為小駝峰形式(首字母小寫)。 - 格式:
CaseCamelLower(s string) string- 示例:
func ExampleCaseCamelLower() {
var (
str = `hello world`
result = gstr.CaseCamelLower(str)
)
fmt.Println(result)
// Output:
// helloWorld
}CaseSnake
- 說明:?
CaseSnake?將字符串轉(zhuǎn)換中的符號(下劃線,空格,點,中橫線)用下劃線( ?_? )替換,并全部轉(zhuǎn)換為小寫字母。 - 格式:
CaseSnake(s string) string- 示例:
func ExampleCaseSnake() {
var (
str = `hello world`
result = gstr.CaseSnake(str)
)
fmt.Println(result)
// Output:
// hello_world
}CaseSnakeScreaming
- 說明:?
CaseSnakeScreaming?把字符串中的符號(下劃線,空格,點,中橫線),全部替換為下劃線?'_'?,并將所有英文字母轉(zhuǎn)為大寫。 - 格式:
CaseSnakeScreaming(s string) string- 示例:
func ExampleCaseSnakeScreaming() {
var (
str = `hello world`
result = gstr.CaseSnakeScreaming(str)
)
fmt.Println(result)
// Output:
// HELLO_WORLD
}CaseSnakeFirstUpper
- 說明:?
CaseSnakeFirstUpper?將字符串中的字母為大寫時,將大寫字母轉(zhuǎn)換為小寫字母并在其前面增加一個下劃線?'_'?,首字母大寫時,只轉(zhuǎn)換為小寫,前面不增加下劃線?'_'? - 格式:
CaseSnakeFirstUpper(word string, underscore ...string) string- 示例:
func ExampleCaseSnakeFirstUpper() {
var (
str = `RGBCodeMd5`
result = gstr.CaseSnakeFirstUpper(str)
)
fmt.Println(result)
// Output:
// rgb_code_md5
}CaseKebab
- 說明:?
CaseKebab?將字符串轉(zhuǎn)換中的符號(下劃線,空格,點,)用中橫線?'-'?替換,并全部轉(zhuǎn)換為小寫字母。 - 格式:
CaseKebab(s string) string- 示例:
func ExampleCaseKebab() {
var (
str = `hello world`
result = gstr.CaseKebab(str)
)
fmt.Println(result)
// Output:
// hello-world
}CaseKebabScreaming
- 說明:?
CaseKebabScreaming?將字符串轉(zhuǎn)換中的符號(下劃線,空格,點,中橫線)用中橫線?'-'?替換,并全部轉(zhuǎn)換為大寫字母。 - 格式:
CaseKebabScreaming(s string) string- 示例:
func ExampleCaseKebabScreaming() {
var (
str = `hello world`
result = gstr.CaseKebabScreaming(str)
)
fmt.Println(result)
// Output:
// HELLO-WORLD
}CaseDelimited
- 說明:?
CaseDelimited?將字符串轉(zhuǎn)換中的符號進(jìn)行替換。 - 格式:
CaseDelimited(s string, del byte) string- 示例:
func ExampleCaseDelimited() {
var (
str = `hello world`
del = byte('-')
result = gstr.CaseDelimited(str, del)
)
fmt.Println(result)
// Output:
// hello-world
}CaseDelimitedScreaming
- 說明:?
CaseDelimitedScreaming?將字符串中的符號(空格,下劃線,點,中橫線)用第二個參數(shù)進(jìn)行替換,該函數(shù)第二個參數(shù)為替換的字符,第三個參數(shù)為大小寫轉(zhuǎn)換,?true?為全部轉(zhuǎn)換大寫字母,?false?為全部轉(zhuǎn)為小寫字母。 - 格式:
CaseDelimitedScreaming(s string, del uint8, screaming bool) string- 示例:
func ExampleCaseDelimitedScreaming() {
{
var (
str = `hello world`
del = byte('-')
result = gstr.CaseDelimitedScreaming(str, del, true)
)
fmt.Println(result)
}
{
var (
str = `hello world`
del = byte('-')
result = gstr.CaseDelimitedScreaming(str, del, false)
)
fmt.Println(result)
}
// Output:
// HELLO-WORLD
// hello-world
} 名稱欄目:創(chuàng)新互聯(lián)GoFrame教程:GoFramegstr-命名轉(zhuǎn)換
當(dāng)前URL:http://www.dlmjj.cn/article/djoehpe.html


咨詢
建站咨詢
