Created
March 17, 2014 05:24
-
-
Save auycro/9594386 to your computer and use it in GitHub Desktop.
CSVParser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/csv" | |
"fmt" | |
"io" | |
"os" | |
) | |
func main() { | |
file, err := os.Open("test.csv") | |
if err != nil { | |
fmt.Println("Error:", err) | |
return | |
} | |
defer file.Close() | |
reader := csv.NewReader(file) | |
RowNum := 0 | |
for { | |
record, err := reader.Read() | |
if err == io.EOF { | |
break | |
} else if err != nil { | |
fmt.Println("Error:", err) | |
return | |
} | |
fmt.Printf("%d:",RowNum) | |
for i:=0;i<len(record);i++{ | |
fmt.Print(record[i]+",") // record has the type []string | |
} | |
fmt.Println() | |
RowNum = RowNum+1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment