1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-10 15:52:27 +08:00

doc: add doc for WriteMapsToCsv

This commit is contained in:
dudaodong
2024-01-01 17:40:32 +08:00
parent 3482f80d1c
commit 4afc838937
9 changed files with 159 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ package fileutil
import (
"fmt"
"io"
"log"
"os"
)
@@ -331,6 +332,27 @@ func ExampleWriteCsvFile() {
// [[Lili 22 female] [Jim 21 male]]
}
func ExampleWriteMapsToCsv() {
csvFilePath := "./testdata/test3.csv"
records := []map[string]string{
{"Name": "Lili", "Age": "22", "gender": "female"},
{"Name": "Jim", "Age": "21", "gender": "male"},
}
err := WriteMapsToCsv(csvFilePath, records, false, ';')
if err != nil {
log.Fatal(err)
}
content, err := ReadCsvFile(csvFilePath, ';')
fmt.Println(content)
// Output:
// [[Name Age gender] [Lili 22 female] [Jim 21 male]]
}
func ExampleWriteStringToFile() {
filepath := "./test.txt"