c# - 如何用嵌入的引号字符串拆分逗号分隔的字符串?

标签 c# .net

我有一个字符串,我想将这个字符串拆分成一个数组,如下所示:

string stemp = "a,b,c,\"d,e f\",g,h";
array[0] = a
array[1] = b
array[2] = c
array[3] = d,e f
array[4] = g
array[5] = h

我试过遵循语法

string array[] = null;
array = stemp.split(',');

最佳答案

这看起来像 CSV - 解析起来不是那么简单(考虑到转义)。

我建议使用 CSV 解析器,例如 TextFieldParser Microsoft.VisualBasic.FileIO 命名空间中的类。

有很多选择,比如FileHelpers .

关于c# - 如何用嵌入的引号字符串拆分逗号分隔的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9498113/

相关文章:

c# - 我如何在 dot net Core 中排列应用程序 dll 文件

c# - 使用 RichTextBox.SelectionFont 时出现 nullReferenceException

.net - 连接到 Oracle 数据源时,OdbcDataReader 会去除小数点

c# - 网站在 MVC Controller 上请求 "Authentication Required",而不是其他 Controller

c# - if else 和 return 的区别

c# - 预加载多对多 - EF Core

c# - 检查现金抽屉是打开还是关闭

c# - 使用 c# 和 TLSv1.2 连接到 LDAP

c# - 如何在不使用第三方 dll 的情况下使用 dotnet framework 4.0 提取 zip 文件

c# - Selenium.WebDriver.ChromeDriver 启动缓慢 - 为什么?