Package strings
implement simple functions to manipulate UTF-8 encoded strings.
Unlike JavaScript, strings are defined between double quotes “…”, not single quotes. Strings in Go are UTF-8
encoded by default. Due to UTF-8
encoding, Golang strings can contain a text which has characters from any language in the world.
package mainimport "fmt"func main() {var s string = "Hello, World"fmt.Printf(s)}
package mainimport "fmt"func main() {var s string = "Hello, World"fmt.Printf("%d",len(s))}
package mainimport "fmt"func main() {var s string = "Hello, World"// Uncomment the following line to change a value// in the string. A error will be thrown.// s[1] = 'c'fmt.Printf("%s",s)}
package mainimport "fmt"func main() {var s string = "Hello, World"for index, character := range(s){fmt.Printf("The character %c is in position %d \n", character, index)}}
package mainimport "fmt"func main() {myslice := []byte{0x48, 0x65, 0x6C, 0x6C, 0x6f}mystring := string(myslice)fmt.Printf(mystring)}
Further functions related to string operations can be found in the official documentation page.
Free Resources