2 go 字符串处理

package main

import "fmt"

import "strings"

func main() {

var a string = "hello"

var b string = "world"

//拼接

c := a + b + "good"

fmt.Println("c = " + c)

//截取

index := strings.Index(c, "good")

if -1 != index {

substr := c[0:index]

fmt.Println("substr = " + substr)

} else {

fmt.Println("no string")

}

//遍历

for i, v := range c {

fmt.Println(i, v)

}

}

你可能感兴趣的:(2 go 字符串处理)