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: ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.