官术网_书友最值得收藏!

String

Go comes with a string type as well as a strings package with a suite of useful functions such as Contains(), Join(), Replace(), Split(), Trim(), and ToUpper(). There is additionally a strconv package dedicated to converting various data types to and from strings. You can read more about the strings package at https://golang.org/pkg/strings/, and the strconv package at https://golang.org/pkg/strconv/.

Double quotes are used for strings. Single quotes are used only for an individual character or runes, not strings. Strings can be defined using the long form or short form with the declare-and-assign operator. You can also use the ` (backticks) symbol to encapsulate strings that span multiple lines. Here is a short example of string usage:

package main

import "fmt"

func main() {
// Long form assignment
var myText = "test string 1"

// Short form assignment
myText2 := "test string 2"

// Multiline string
myText3 := `long string
spanning multiple
lines`
fmt.Println(myText) fmt.Println(myText2) fmt.Println(myText3)
}
主站蜘蛛池模板: 宣城市| 南投县| 梨树县| 大埔县| 基隆市| 高邑县| 保德县| 沙洋县| 广水市| 余庆县| 甘洛县| 连州市| 巩义市| 临邑县| 望江县| 乳源| 子洲县| 蓬溪县| 松溪县| 晋州市| 福鼎市| 师宗县| 平远县| 包头市| 咸阳市| 邵东县| 称多县| 上虞市| 横峰县| 班戈县| 翁牛特旗| 卫辉市| 中宁县| 杭锦后旗| 扬中市| 云龙县| 且末县| 红桥区| 河曲县| 广灵县| 辽宁省|