- 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)
}
推薦閱讀
- 線性代數及其應用(原書第6版)
- Hands-On Blockchain Development in 7 Days
- Data Visualization:a successful design process
- 模式識別與人工智能(基于MATLAB)
- Origin 9.0科技繪圖與數據分析超級學習手冊
- Blockchain Quick Reference
- 高等數學習題全解(下冊)
- The Modern C# Challenge
- 物性數學及其應用
- CAE分析大系:ANSYS疑難問題實例詳解
- 幾何公差那些事兒
- 基于變分法的細胞演化建模
- 代數的歷史:人類對未知量的不舍追蹤(修訂版)
- 高等數學習題全解與學習指導(下冊)
- 數學故事總動員