Format and remove 07.6.md spaces
This commit is contained in:
174
zh/07.6.md
174
zh/07.6.md
@@ -9,15 +9,15 @@
|
||||
|
||||
```Go
|
||||
|
||||
fmt.Println(strings.Contains("seafood", "foo"))
|
||||
fmt.Println(strings.Contains("seafood", "bar"))
|
||||
fmt.Println(strings.Contains("seafood", ""))
|
||||
fmt.Println(strings.Contains("", ""))
|
||||
//Output:
|
||||
//true
|
||||
//false
|
||||
//true
|
||||
//true
|
||||
fmt.Println(strings.Contains("seafood", "foo"))
|
||||
fmt.Println(strings.Contains("seafood", "bar"))
|
||||
fmt.Println(strings.Contains("seafood", ""))
|
||||
fmt.Println(strings.Contains("", ""))
|
||||
//Output:
|
||||
//true
|
||||
//false
|
||||
//true
|
||||
//true
|
||||
|
||||
```
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
|
||||
```Go
|
||||
|
||||
s := []string{"foo", "bar", "baz"}
|
||||
fmt.Println(strings.Join(s, ", "))
|
||||
//Output:foo, bar, baz
|
||||
s := []string{"foo", "bar", "baz"}
|
||||
fmt.Println(strings.Join(s, ", "))
|
||||
//Output:foo, bar, baz
|
||||
```
|
||||
|
||||
- func Index(s, sep string) int
|
||||
@@ -38,10 +38,10 @@
|
||||
|
||||
```Go
|
||||
|
||||
fmt.Println(strings.Index("chicken", "ken"))
|
||||
fmt.Println(strings.Index("chicken", "dmr"))
|
||||
//Output:4
|
||||
//-1
|
||||
fmt.Println(strings.Index("chicken", "ken"))
|
||||
fmt.Println(strings.Index("chicken", "dmr"))
|
||||
//Output:4
|
||||
//-1
|
||||
```
|
||||
- func Repeat(s string, count int) string
|
||||
|
||||
@@ -49,8 +49,8 @@
|
||||
|
||||
```Go
|
||||
|
||||
fmt.Println("ba" + strings.Repeat("na", 2))
|
||||
//Output:banana
|
||||
fmt.Println("ba" + strings.Repeat("na", 2))
|
||||
//Output:banana
|
||||
```
|
||||
- func Replace(s, old, new string, n int) string
|
||||
|
||||
@@ -58,10 +58,10 @@
|
||||
|
||||
```Go
|
||||
|
||||
fmt.Println(strings.Replace("oink oink oink", "k", "ky", 2))
|
||||
fmt.Println(strings.Replace("oink oink oink", "oink", "moo", -1))
|
||||
//Output:oinky oinky oink
|
||||
//moo moo moo
|
||||
fmt.Println(strings.Replace("oink oink oink", "k", "ky", 2))
|
||||
fmt.Println(strings.Replace("oink oink oink", "oink", "moo", -1))
|
||||
//Output:oinky oinky oink
|
||||
//moo moo moo
|
||||
```
|
||||
- func Split(s, sep string) []string
|
||||
|
||||
@@ -69,14 +69,14 @@
|
||||
|
||||
```Go
|
||||
|
||||
fmt.Printf("%q\n", strings.Split("a,b,c", ","))
|
||||
fmt.Printf("%q\n", strings.Split("a man a plan a canal panama", "a "))
|
||||
fmt.Printf("%q\n", strings.Split(" xyz ", ""))
|
||||
fmt.Printf("%q\n", strings.Split("", "Bernardo O'Higgins"))
|
||||
//Output:["a" "b" "c"]
|
||||
//["" "man " "plan " "canal panama"]
|
||||
//[" " "x" "y" "z" " "]
|
||||
//[""]
|
||||
fmt.Printf("%q\n", strings.Split("a,b,c", ","))
|
||||
fmt.Printf("%q\n", strings.Split("a man a plan a canal panama", "a "))
|
||||
fmt.Printf("%q\n", strings.Split(" xyz ", ""))
|
||||
fmt.Printf("%q\n", strings.Split("", "Bernardo O'Higgins"))
|
||||
//Output:["a" "b" "c"]
|
||||
//["" "man " "plan " "canal panama"]
|
||||
//[" " "x" "y" "z" " "]
|
||||
//[""]
|
||||
```
|
||||
|
||||
- func Trim(s string, cutset string) string
|
||||
@@ -85,8 +85,8 @@
|
||||
|
||||
```Go
|
||||
|
||||
fmt.Printf("[%q]", strings.Trim(" !!! Achtung !!! ", "! "))
|
||||
//Output:["Achtung"]
|
||||
fmt.Printf("[%q]", strings.Trim(" !!! Achtung !!! ", "! "))
|
||||
//Output:["Achtung"]
|
||||
```
|
||||
|
||||
- func Fields(s string) []string
|
||||
@@ -95,8 +95,8 @@
|
||||
|
||||
```Go
|
||||
|
||||
fmt.Printf("Fields are: %q", strings.Fields(" foo bar baz "))
|
||||
//Output:Fields are: ["foo" "bar" "baz"]
|
||||
fmt.Printf("Fields are: %q", strings.Fields(" foo bar baz "))
|
||||
//Output:Fields are: ["foo" "bar" "baz"]
|
||||
```
|
||||
|
||||
## 字符串转换
|
||||
@@ -106,41 +106,41 @@
|
||||
|
||||
```Go
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
str := make([]byte, 0, 100)
|
||||
str = strconv.AppendInt(str, 4567, 10)
|
||||
str = strconv.AppendBool(str, false)
|
||||
str = strconv.AppendQuote(str, "abcdefg")
|
||||
str = strconv.AppendQuoteRune(str, '单')
|
||||
fmt.Println(string(str))
|
||||
}
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
str := make([]byte, 0, 100)
|
||||
str = strconv.AppendInt(str, 4567, 10)
|
||||
str = strconv.AppendBool(str, false)
|
||||
str = strconv.AppendQuote(str, "abcdefg")
|
||||
str = strconv.AppendQuoteRune(str, '单')
|
||||
fmt.Println(string(str))
|
||||
}
|
||||
```
|
||||
|
||||
- Format 系列函数把其他类型的转换为字符串
|
||||
```Go
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
a := strconv.FormatBool(false)
|
||||
b := strconv.FormatFloat(123.23, 'g', 12, 64)
|
||||
c := strconv.FormatInt(1234, 10)
|
||||
d := strconv.FormatUint(12345, 10)
|
||||
e := strconv.Itoa(1023)
|
||||
fmt.Println(a, b, c, d, e)
|
||||
}
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
a := strconv.FormatBool(false)
|
||||
b := strconv.FormatFloat(123.23, 'g', 12, 64)
|
||||
c := strconv.FormatInt(1234, 10)
|
||||
d := strconv.FormatUint(12345, 10)
|
||||
e := strconv.Itoa(1023)
|
||||
fmt.Println(a, b, c, d, e)
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -148,30 +148,30 @@
|
||||
|
||||
```Go
|
||||
|
||||
package main
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
func checkError(e error){
|
||||
if e != nil{
|
||||
fmt.Println(e)
|
||||
}
|
||||
}
|
||||
func main() {
|
||||
a, err := strconv.ParseBool("false")
|
||||
checkError(err)
|
||||
b, err := strconv.ParseFloat("123.23", 64)
|
||||
checkError(err)
|
||||
c, err := strconv.ParseInt("1234", 10, 64)
|
||||
checkError(err)
|
||||
d, err := strconv.ParseUint("12345", 10, 64)
|
||||
checkError(err)
|
||||
e, err := strconv.Atoi("1023")
|
||||
checkError(err)
|
||||
fmt.Println(a, b, c, d, e)
|
||||
}
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
func checkError(e error){
|
||||
if e != nil{
|
||||
fmt.Println(e)
|
||||
}
|
||||
}
|
||||
func main() {
|
||||
a, err := strconv.ParseBool("false")
|
||||
checkError(err)
|
||||
b, err := strconv.ParseFloat("123.23", 64)
|
||||
checkError(err)
|
||||
c, err := strconv.ParseInt("1234", 10, 64)
|
||||
checkError(err)
|
||||
d, err := strconv.ParseUint("12345", 10, 64)
|
||||
checkError(err)
|
||||
e, err := strconv.Atoi("1023")
|
||||
checkError(err)
|
||||
fmt.Println(a, b, c, d, e)
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user