练习fmt方法
package main
import (
"fmt"
"math"
"strings"
)
const (
name = "王龙"
age = 18
isOK = true
)
var (
name1 string
age1 int
isOK1 bool
)
func main() {
name1 = "王龙1"
age1 = 19
isOK1 = true
fmt.Println(name)
fmt.Println(age)
fmt.Println(isOK)
fmt.Println(name1)
fmt.Println(age1)
fmt.Println(isOK1)
fmt.Printf("%f
", math.Pi)
fmt.Printf("%.2f
", math.Pi)
s1 := "hello"
s2 := "你好"
fmt.Printf("%s
", s1)
fmt.Printf("%s
", s2)
s4 := "hello中国"
for i := 0; i < len(s4); i++ {
fmt.Printf("%v(%c)",s4[i],s4[i])
}
b1 :=true
var b2 bool
fmt.Printf("%T
",b1)
fmt.Printf("%T value:%v
",b2,b2)
path := "/Users/ianthony/Desktop/anthonyProject"
fmt.Printf("%s
",path)
s3 := `第一
第二
第三`
fmt.Printf("%s",s3)
name := "理想"
world := "北京"
// 字符串拼接
ss := name + world
fmt.Println(ss)
// 字符串拼接
ss1 := fmt.Sprintf("%s%s",name,world)
fmt.Println(ss1)
// 字符串拼接
ret := strings.Split(path,"/")
fmt.Println(ret)
// 判断是否包含
fmt.Println(strings.Contains(path,"ianthony"))
// 判断是否以/开头
fmt.Println(strings.HasPrefix(path,"/"))
// 判断是否以t结尾
fmt.Println(strings.HasSuffix(path,"t"))
// 判断j的索引值是多少
s5 := "abcdefj"
fmt.Println(strings.Index(s5,"j"))
// 拼接
fmt.Println(strings.Join(ret,"/"))
fmt.Println(strings.Join(ret,"+"))
// 遍历字符串
s := "hello沙河"
for i := 0; i < len(s); i++ { //byte
fmt.Printf("%c ", s[i])
}
fmt.Println()
for _, r := range s { //rune
fmt.Printf("%c ", r)
}
fmt.Println()
// 数据类型强制转换
n := 10
var f float64
f = float64(n)
fmt.Println(f)
}