Working With Strings


Strings can be treated like arrays

package main

import (
    "fmt"
    "reflect"
)

func main() {
    strVar := "hello world"
    fmt.Println(strVar[:5])
    fmt.Println(strVar[:5] == "hello")

    newStr := strVar[:5]
    fmt.Println(newStr)
    fmt.Println(reflect.TypeOf(newStr))

Output

hello
true
hello
string

results matching ""

    No results matching ""