go 的字符查看位置
多个fmt.Scanf()输入方式:
Please Input Str: Please Input Substr: str=asdfsadfadsafdfddsfsad,substr=d
输出:2 21
点击查看代码
package main
import (
"fmt"
"strings"
)
func StrIndex(str string, substr string) (int, int) {
fmt.Printf("str=%s,substr=%s \n",str,substr)
return strings.Index(str, substr), strings.LastIndex(str, substr)
}
func main() {
var (
str string
substr string
)
fmt.Printf("Please Input Str: ")
fmt.Scanf("%s", &str)
fmt.Printf("Please Input Substr: ")
fmt.Scanf("%s", &substr)
fmt.Println(StrIndex(str, substr))
}
写入自己的博客中才能记得长久