Standard library / fmt

fmt.Sscan()

Reads values from a string into pointer arguments. Whitespace separates values, including newlines. Returns number of successfully assigned items and error; partial success is possible. A successful scan need not validate all remaining input. Expected stdout: '2 12 red <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func Sscan(str string, a ...any) (n int, err error)

Parameters & Attributes

NameTypeDescription
strstringInput text to scan.
a...anyDestination pointers or Scanner implementations, one for each value to scan.

Return Value

(n int, err error)

Number of assigned operands and scan error.

Working Example

Example Snippetgo
package main
import (  "fmt")
func main() {  var n int  var word string  count, e := fmt.Sscan("12 red", &n, &word)  fmt.Println(count, n, word, e)}
Go Reference