逗号分隔的文本 [英] Comma delimited text

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

问题描述

我有以下字符串:


" smith"," Joe"," West Palm Beach,Fl。"


我需要根据逗号分割这个字符串,但是当你看到这个城市时,

state包含一个逗号。 String.split将溢出城市状态。是否有一个

内置函数,我将丢失它将执行拆分并识别

城市状态中的逗号是项目的一部分?


-

谢谢

Wayne Sepega

杰克逊维尔,佛罗里达

" ;当一个男人和一个漂亮的女孩坐在一起一小时,似乎只有一分钟。但是

让他坐在热炉上一分钟,它比任何一小时都要长。

那是'相对论'。 - 阿尔伯特爱因斯坦

I have the following string:

"smith", "Joe", "West Palm Beach, Fl."

I need to split this string based on the commas, but as you see the city
state contains a comma. String.split will spilt the city state. Is there a
built in function that I''m missing that will do the split and recognize that
the comma in city state is part of the item?

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it''s longer than any hour.
That''s relativity." - Albert Einstein

推荐答案

您可能需要完全拆分它然后重新加入城市和

状态字段如果你想完成你要求的话,请使用逗号。

C#和.Net都不能识别任何其他逗号中的城市,状态字符串

分隔字符串。


如果城市,州对在

字符串中的固定点(以逗号计数),你可以用其他一些逗号替换所有其他逗号唯一字符串

并拆分该唯一字符串,或更改城市,状态逗号使用,

或许,string.LastIndexOf()并仍然在逗号上拆分。 />

我很好奇,为什么你想保留城市,作为单个数据说明
项目。在一般实践中,它们应作为单独的项目处理。


HTH


DalePres

MCAD,MCDBA ,MCSE


" Wayne" <我****** @ community.nospam>在消息中写道

新闻:好的************* @ TK2MSFTNGP12.phx.gbl ...
You probably will have to split it completely then re-join the city and
state fields with a comma if you want to accomplish what you''re asking.
Neither C# nor .Net can recognize a city,state string from any other comma
delimited string.

If the city,state pair are at a fixed point (in terms of comma count) in the
string you could replace all the other commas with some other unique string
and split on that unique string, or change the city,state comma using,
perhaps, string.LastIndexOf() and still split on the comma.

I am curious, though, why you would want to keep city,state as a single data
item. In general practice, they should be dealt with as separate items.

HTH

DalePres
MCAD, MCDBA, MCSE

"Wayne" <Me******@community.nospam> wrote in message
news:Ok*************@TK2MSFTNGP12.phx.gbl...
我有以下字符串:

" smith"," Joe"," West Palm Beach,Fl。"

我需要根据逗号分割这个字符串,但就像你一样看到这个城市
状态包含一个逗号。 String.split将溢出城市状态。是否有一个内置的功能,我将失去它将进行拆分并识别

城市状态中的逗号是项目的一部分?
-
谢谢
Wayne Sepega
杰克逊维尔,佛罗里达

"当一个男人和一个漂亮女孩坐在一起一小时后,似乎只需一分钟。但是
让他坐在热炉上一分钟,这比任何一小时都要长。
这就是相对论。 - 阿尔伯特爱因斯坦
I have the following string:

"smith", "Joe", "West Palm Beach, Fl."

I need to split this string based on the commas, but as you see the city
state contains a comma. String.split will spilt the city state. Is there a
built in function that I''m missing that will do the split and recognize
that
the comma in city state is part of the item?

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute.
But
let him sit on a hot stove for a minute and it''s longer than any hour.
That''s relativity." - Albert Einstein



不,但先做替换并用另一个角色替换逗号,

这样作为;这将允许您在逗号上正确分割。


然后您可以在包含城市/州的数组元素上运行替换

并替换;再次使用逗号。


-

Gerry O''Brien

Visual Basic.NET MVP

" Wayne" <我****** @ community.nospam>在消息中写道

新闻:好的************* @ TK2MSFTNGP12.phx.gbl ...
No, but do a replace first and replace the comma with another character,
such as ;. This will allow you to split correctly on the commas.

Then you can run replace on the array element that contains the city/state
and replace the ; with a comma again.

--
Gerry O''Brien
Visual Basic.NET MVP
"Wayne" <Me******@community.nospam> wrote in message
news:Ok*************@TK2MSFTNGP12.phx.gbl...
我有以下字符串:

" smith"," Joe"," West Palm Beach,Fl。"

我需要根据逗号分割这个字符串,但就像你一样看到这个城市
状态包含一个逗号。 String.split将溢出城市状态。是否有一个内置的功能,我将失去它将进行拆分并识别

城市状态中的逗号是项目的一部分?
-
谢谢
Wayne Sepega
杰克逊维尔,佛罗里达

"当一个男人和一个漂亮女孩坐在一起一小时后,似乎只需一分钟。但是
让他坐在热炉上一分钟,这比任何一小时都要长。
这就是相对论。 - 阿尔伯特爱因斯坦
I have the following string:

"smith", "Joe", "West Palm Beach, Fl."

I need to split this string based on the commas, but as you see the city
state contains a comma. String.split will spilt the city state. Is there a
built in function that I''m missing that will do the split and recognize
that
the comma in city state is part of the item?

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute.
But
let him sit on a hot stove for a minute and it''s longer than any hour.
That''s relativity." - Albert Einstein



嗨Wayne,


这称为CSV文件,取一个看看
http://www.opennetcf.org/SourceBrows...DataAdapter.cs


你会发现一个针对这类文件的DataProvider,也查了昨天

个帖子,发布了一个类似的问题&昨天回答。


干杯,


-

Ignacio Machin,

ignacio.machin AT dot.state.fl.us

佛罗里达州交通部

" Wayne" <我****** @ community.nospam>在消息中写道

新闻:好的************* @ TK2MSFTNGP12.phx.gbl ...
Hi Wayne,

This is called a CSV file, take a look at
http://www.opennetcf.org/SourceBrows...DataAdapter.cs

you will find a DataProvider for this kind of files, also check yesterdays
threads, A similar question was posted & answered yesterday.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Wayne" <Me******@community.nospam> wrote in message
news:Ok*************@TK2MSFTNGP12.phx.gbl...
我有以下字符串:

" smith"," Joe"," West Palm Beach,Fl。"

我需要根据逗号分割这个字符串,但就像你一样看到这个城市
状态包含一个逗号。 String.split将溢出城市状态。是否有一个内置的功能,我将失去它将进行拆分并识别

城市状态中的逗号是项目的一部分?
-
谢谢
Wayne Sepega
杰克逊维尔,佛罗里达

"当一个男人和一个漂亮女孩坐在一起一小时后,似乎只需一分钟。但是
让他坐在热炉上一分钟,这比任何一小时都要长。
这就是相对论。 - 阿尔伯特爱因斯坦
I have the following string:

"smith", "Joe", "West Palm Beach, Fl."

I need to split this string based on the commas, but as you see the city
state contains a comma. String.split will spilt the city state. Is there a
built in function that I''m missing that will do the split and recognize
that
the comma in city state is part of the item?

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute.
But
let him sit on a hot stove for a minute and it''s longer than any hour.
That''s relativity." - Albert Einstein



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

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