解析以逗号分隔的记录? [英] Parsing Comma-delimited records?

查看:93
本文介绍了解析以逗号分隔的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解析一个以逗号分隔的记录,但如果字符串中的某些字符串在"之间,我希望它可以执行某些操作。我怎样才能做到这一点?使用Excel导入它确实是正确的
。我正在使用String.Split()。

基本上,这就是我想要做的事情:在整个字符串上使用string.Split()

除了字符串介于双引号之间。字符串中的部分

介于"之间。将被String.Split忽略


谢谢。

I''m parsing a comma-delimited record but I want it to do something if some of
the string is between "". How can I do this? With the Excel import it does
it correct. I''m using String.Split().
Basically, this is what I want to do: Use string.Split() on the whole string
UNLESS the string is in between double-quotes. The part of the string
in-between the "" will be ignored by String.Split

Thanks.

推荐答案



VMI写道:

VMI wrote:

我正在解析一个以逗号分隔的记录,但我想要它做一些事情如果

这个字符串是在...之间。我怎样才能做到这一点?使用Excel导入它确实是正确的
。我正在使用String.Split()。

基本上,这就是我想要做的事情:在整个字符串上使用string.Split()

除了字符串介于双引号之间。字符串中的部分

介于"之间。将被String.Split忽略
I''m parsing a comma-delimited record but I want it to do something if some of
the string is between "". How can I do this? With the Excel import it does
it correct. I''m using String.Split().
Basically, this is what I want to do: Use string.Split() on the whole string
UNLESS the string is in between double-quotes. The part of the string
in-between the "" will be ignored by String.Split



我会放弃String.Split并自行拆分字符串,处理

引号和转义字符有必要的。这是一个非常简单的小b循环,易于编写和维护。有时

框架提供的方法不是解决问题的最佳方法,

恕我直言。


除非有人否则有一个聪明的伎俩......?

I would abandon String.Split and split the string myself, coping with
quotation marks and escape characters as necessary. It''s a very simple
little loop to do it, easy to write and maintain. Sometimes the
Framework-supplied methods aren''t the best way to solve a problem,
IMHO.

Unless someone else has a clever trick...?


VMI,


你将不得不循环通过字符串逐字符和

注意状态,或者在这种情况下使用正则表达式。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv * @ spam.guard.caspershouse.com


" VMI" < VM*@discussions.microsoft.com写信息

新闻:BA *************************** ******* @ microsof t.com ...
VMI,

You will have to cycle through the string character by character and
take note of the state, or use regular expressions in this case.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"VMI" <VM*@discussions.microsoft.comwrote in message
news:BA**********************************@microsof t.com...

我正在解析一个以逗号分隔的记录,但我希望它可以做一些事情,如果有的话



字符串在"之间。我怎样才能做到这一点?随着Excel导入它

确实

它是正确的。我正在使用String.Split()。

基本上,这就是我想要做的事情:整个上使用string.Split()

string

除非字符串在双引号之间。字符串中的部分

介于"之间。将被String.Split忽略


谢谢。
I''m parsing a comma-delimited record but I want it to do something if some
of
the string is between "". How can I do this? With the Excel import it
does
it correct. I''m using String.Split().
Basically, this is what I want to do: Use string.Split() on the whole
string
UNLESS the string is in between double-quotes. The part of the string
in-between the "" will be ignored by String.Split

Thanks.



这是我博客上的方法。

http://staceyw.spaces.msn.com /blog/cns!F4A38E96E598161E!352.entry?


-

William Stacey [MVP]


" VMI" < VM*@discussions.microsoft.com写信息

新闻:BA *************************** ******* @ microsof t.com ...

|我正在解析一个以逗号分隔的记录,但我希望它可以做一些事情



|字符串在之间。我怎样才能做到这一点?用Excel导入它

确实

|它是正确的。我正在使用String.Split()。

|基本上,这就是我想要做的事情:整体上使用string.Split()

字符串

|除非字符串在双引号之间。字符串的一部分

|在...之间将被String.Split忽略

|

|谢谢。
Here is a method on my blog.
http://staceyw.spaces.msn.com/blog/cns!F4A38E96E598161E!352.entry?

--
William Stacey [MVP]

"VMI" <VM*@discussions.microsoft.comwrote in message
news:BA**********************************@microsof t.com...
| I''m parsing a comma-delimited record but I want it to do something if some
of
| the string is between "". How can I do this? With the Excel import it
does
| it correct. I''m using String.Split().
| Basically, this is what I want to do: Use string.Split() on the whole
string
| UNLESS the string is in between double-quotes. The part of the string
| in-between the "" will be ignored by String.Split
|
| Thanks.


这篇关于解析以逗号分隔的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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