Comma delimited text

W

Wayne

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
 
D

DalePres

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
 
G

Gerry O'Brien

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.
 
W

Wayne

City state was just the first thing I thought of that would have a comma,
and needed an example for the post. I've got some test data that may have
Commas in it, but didn't have it handy.

Thanks for the input.
Wayne
 
W

Wayne

I saw yesterday's post, he was wanting to validate the data, that post is
what reminded me about this issue.

Thanks for the link, I will check it out.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

The dataprovider do all the processing logic for you, all you have to do is
create a connection and call dataaccess.fill just like you do with the SQL
data provider,
IMHO It's very good piece of work !!!

cheers,
 
J

Jon Skeet [C# MVP]

Gerry O'Brien said:
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.

The replace would need to know which commas to replace with ; though -
a simple String.Replace wouldn't help you there, although a clever
regular expression might.
 
G

Gerry O'Brien

You would if it is it is the last comma in the line as his sample showed. I
guess it depends on if his input would be in the same format every time.
 
C

Christian Wilhelm

Hi Wayne,
"smith", "Joe", "West Palm Beach, Fl."
Perhaps it is also an approach for you, too look for ", "
(Quote+Comma+Space+Quote) with IndexOf.

Sincerly,
Christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

XmlCodeExporter 3
TollBox Pushpin effect 2
Beta 2 News Groups 1
Profiling tool for C# and .net 2.0 2
windows form datagrid questions 2
XmlSerializer 3
///Summary <-- help file generation 2
Formless application 11

Top