Standard library / encoding/csv

encoding/csv.Reader.FieldPos()

Return the one-based line and byte column of a field in the most recently returned record. Out-of-range field indices panic. Expected stdout: '1 4\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Reader) FieldPos(field int) (line, column int)

Parameters & Attributes

NameTypeDescription
fieldintZero-based field index in the most recently read record.

Return Value

(line, column int)

One-based line and byte column.

Working Example

Example Snippetgo
package main
import (  "encoding/csv"  "fmt"  "strings")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  r := csv.NewReader(strings.NewReader("é,x\n"))  _, e := r.Read()  must(e)  a, b := r.FieldPos(1)  fmt.Println(a, b)}
Go Reference