- 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)
}
推薦閱讀
- 432級(jí)臺(tái)階之第2級(jí)臺(tái)階
- 線性代數(shù)選講
- Introduction to Blockchain and Ethereum
- 奇妙數(shù)學(xué)史:數(shù)字與生活
- 尖叫的數(shù)學(xué):令人驚嘆的數(shù)學(xué)之美
- 迷人的邏輯題
- 一個(gè)數(shù)學(xué)家的辯白(雙語版)
- Blockchain for Decision Makers
- 迷人的數(shù)學(xué)(全2冊(cè))
- 美妙的數(shù)學(xué)(插圖珍藏版)
- 燒腦的邏輯題
- 人大附小的課堂四聲(人大附小七彩教育成果叢書)
- 復(fù)分析:可視化方法
- 別萊利曼的趣味代數(shù)學(xué)
- 挑戰(zhàn)思維極限:勾股定理的365種證明