Standard library / io

io.WriteString()

Writes a string using StringWriter when available, otherwise Write. Returns the accepted byte count and error. Expected stdout: '8 سلام <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func WriteString(w Writer, s string) (n int, err error)

Parameters & Attributes

NameTypeDescription
wWriterDestination writer.
sstringText to write.

Return Value

(n int, err error)

Writes a string using StringWriter when available, otherwise Write.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "io")
func main() {  var b bytes.Buffer  n, e := io.WriteString(&b, "سلام")  fmt.Println(n, b.String(), e)}
Go Reference