1 回答

TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個贊
創(chuàng)建一個io.Reader,它從通過底層 io.Reader 讀取的數(shù)據(jù)中刪除引號。
// rmquote reads r with " removed.
type rmquote struct {
r io.Reader
}
func (c rmquote) Read(p []byte) (int, error) {
n, err := c.r.Read(p)
// i is output position for loop below
i := 0
// for each byte read from the file
for _, b := range p[:n] {
// skip quotes
if b == '"' {
continue
}
// copy byte to output position and advance position
p[i] = b
i++
}
// output position is the new length
return i, err
}
將其插入 CSV 閱讀器和文件之間:
parser := csv.NewReader(rmquote{file})
- 1 回答
- 0 關(guān)注
- 111 瀏覽
添加回答
舉報