我這是從CSV文件來像行拆分逗號分隔的多個字符串在C#
"[email protected]","seattle,US","9999 00000"
預期輸出:
[email protected]
seattle,US
9999 00000
實際輸出,當我做string.Split(',')
:
"[email protected]"
"seattle
US"
"9999 00000"
我這是從CSV文件來像行拆分逗號分隔的多個字符串在C#
"[email protected]","seattle,US","9999 00000"
預期輸出:
[email protected]
seattle,US
9999 00000
實際輸出,當我做string.Split(',')
:
"[email protected]"
"seattle
US"
"9999 00000"
如果您使用"
字符來限定某列,則可以按","
string input = "\"[email protected]\",\"seattle,US\",\"9999 00000\"";
string[] result = input.Trim('"').Split(new string[] { "\",\"" }, StringSplitOptions.None);
還沒有downvoted。但這不是一個很好的方法。分隔符顯然是逗號而不是引號。在這種情況下,雖然 –
@TimSchmelter,但引號甚至存在,如果其內容中沒有逗號 – fubo
如果每行中的每個字段都被引號括起來,那麼對「,」的分割對我來說似乎很好。 ? –
顯示你做了什麼 –
使用一個真正的CSV解析器不string.split –
的'split'不明白你有你的心是什麼 - 是正常工作爲輸出 - 如果你需要一些不同的東西,只是編碼而已。 – Aristos