Comma delimited text

  • Thread starter Thread starter Wayne
  • Start date Start date
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
 
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
 
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.
 
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
 
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.
 
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,
 
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.
 
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.
 
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
 
Back
Top