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

  • Security with Go
  • John Daniel Leon
  • 161字
  • 2021-06-30 19:06:47

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)
}
主站蜘蛛池模板: 合水县| 淮安市| 隆尧县| 祁阳县| 康马县| 云南省| 九寨沟县| 高青县| 西宁市| 新民市| 华池县| 江达县| 金山区| 华坪县| 星子县| 惠东县| 永登县| 九龙城区| 东辽县| 南川市| 新和县| 涞水县| 子长县| 仁寿县| 丹江口市| 武强县| 鹿邑县| 上蔡县| 探索| 泰宁县| 伊通| 霍邱县| 沙河市| 亳州市| 筠连县| 和静县| 龙江县| 中宁县| 和政县| 武汉市| 科尔|