作为一种基本数据结构,每种语言都有一些对于字符串的预定义处理函数。Go 中使用 strings 包来完成对字符串的主要操作。

看一下代码:

package main

import (
    "fmt"
    "strings"
)

func main() {
    s := "ceshi"
    //s字符串时候以"mmm"开头
    fmt.Println(strings.HasPrefix(s, "mmm"))
    //s是否以"hi"结尾
    fmt.Println(strings.HasSuffix(s, "hi"))

    var str string = "This is an example of a string"
    fmt.Printf("T/F? Does the string \"%s\" have prefix %s? ", str, "Th")
    fmt.Printf("%t\n", strings.HasPrefix(str, "Th"))

}

输出:

4.7字符串

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-01-04
  • 2021-09-11
  • 2021-09-08
  • 2021-05-22
猜你喜欢
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案