[Solved] What does String() string exactly do? [closed]


Sometimes you need to incrementally build a new string, i.e. character per character. In order to do this efficiently many programming languages add the so-called string builders. This allows to essentially modify an array of characters rather than recreating a new string every time. Check the official example:

package main

import (
    "fmt"
    "strings"
)

func main() {
    var b strings.Builder
    for i := 3; i >= 1; i-- {
        fmt.Fprintf(&b, "%d...", i)
    }
    b.WriteString("ignition")
    fmt.Println(b.String())

}

String() is the last step when you convert that inner structure into the actual string. Try to play with the example above and assign builder to a string variable and you see that only works when you use String() method

solved What does String() string exactly do? [closed]