parse_csv()parse_csv()

拆分表示单个记录(包含逗号分隔值)的给定字符串,并返回包含这些值的字符串数组。Splits a given string representing a single record of comma-separated values and returns a string array with these values.

parse_csv("aaa,bbb,ccc") == ["aaa","bbb","ccc"]

语法Syntax

parse_csv(source)parse_csv(source)

参数Arguments

  • source:表示单个记录(包含逗号分隔值)的源字符串。source: The source string representing a single record of comma-separated values.

返回Returns

一个包含拆分值的字符串数组。A string array that contains the split values.

备注Notes

可以使用双引号 ('"') 来转义嵌入行的源、逗号和引号。Embedded line feeds, commas, and quotes may be escaped using the double quotation mark ('"'). 此函数不支持每行多条记录(仅获取第一条记录)。This function doesn't support multiple records per row (only the first record is taken).

示例Examples

print result=parse_csv('aa,"b,b,b",cc,"Escaping quotes: ""Title""","line1\nline2"')
resultresult
[[
"aa","aa",
"b,b,b","b,b,b",
"cc","cc",
"Escaping quotes:"Title"","Escaping quotes: "Title"",
"line1\nline2""line1\nline2"
]]

具有多条记录的 CSV 有效负载:CSV payload with multiple records:

print result_multi_record=parse_csv('record1,a,b,c\nrecord2,x,y,z')
result_multi_recordresult_multi_record
[[
"record1","record1",
"a","a",
"b","b",
"c""c"
]]