我如何分割这一行 [英] How do i split this row

查看:100
本文介绍了我如何分割这一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试拆分这一行值:

Hi all, I am trying to split this row of values:

"databasename","DBAName","MerchantNumber","Status","Gateway","ShoppingCart","WebHost","HostingCoLocation","PaymentAppName","PaymentAppVersion","PaymentAppLastValidated","Phone","Registered for Scan","Scanner","ScanDate","ScanStaus","Next Scan Scheduled","SAQType","SAQGroup","SAQ Version","Compliant","dateconfirmed","AttestationName"



我使用过:


I used:

Dim strColumns As String() = row.Split(",")



返回:


This returns:

strColumns(0)="databasename"
            strColumns(1)="DBAName"....etc...



但我需要:


But I need:

strColumns(0)= databasename





我如何实现这个目标?



请帮忙。



谢谢。



How do i achieve this?

Please help.

Thanks.

推荐答案

我想问题是额外的字符。



你需要 row.Split(new char [] {'' '','','',},System.StringSplitOptions.RemoveEmptyEntries); 这就是全部。



-SA
I guess the problem is extra " characters.

You need row.Split(new char[] {''"'', '','', }, System.StringSplitOptions.RemoveEmptyEntries); that''s all.

—SA


虽然谢尔盖的解决方案适用于您展示的具体示例,但我怀疑它会导致后者出现问题。您发布的数据片段看起来像基本的CSV,(或逗号分隔值)数据,如果是这样,那么引用字符串的使用是故意的:它就在那里,所以逗号可以包含在字符串条目中:

While Sergey''s solution will work fine for the specific example you show, I suspect it will cause problems latter on. The data fragment you have posted looks like basic CSV, (or comma separated values) data, and if so, then the use of quoted strings is deliberate: it is there so that commas can be included in string entries:
"abc", "def,ghi", "jkl"

三个条目,而不是四个:

Is three entries, not four:

abc
def,ghi
jkl

虽然你可以使用Sergeys解决方案,(或者只是使用string.Replace(\,)来删除它们都是第一个)我建议你使用一个支持CSV的处理器。

有很多方法可以帮助你做到这一点:

快速CSV阅读器 [ ^ ]



C# - CSV导入导出 [ ^ ]



用C#读取和写入CSV文件 [ ^ ]

While you could use Sergeys solution, (or just use string.Replace("\"", "") to remove them all first) I would recommend that you use a CSV aware processor instead.
There are a number of ways to help you do just that:
A Fast CSV Reader[^]

C# - CSV Import Export[^]

Reading and Writing CSV Files in C#[^]


这篇关于我如何分割这一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆