Standard library / reflect
reflect.Value.SetString()
Change a settable string value through its kind-specific setter. Wrong kinds or non-settable values panic; numeric conversions may narrow. Expected stdout: 'go\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) SetString(x string)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | string | New value; must satisfy the destination kind or assignability requirement. |
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { var x string; reflect.ValueOf(&x).Elem().SetString("go"); fmt.Println(x) }