473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Comma delimited text

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
Nov 16 '05 #1
9 4475
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...
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

Nov 16 '05 #2
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...
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

Nov 16 '05 #3
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...
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

Nov 16 '05 #4
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
"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:Oq**************@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...
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


Nov 16 '05 #5
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.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:eV**************@TK2MSFTNGP10.phx.gbl...
Hi Wayne,

This is called a CSV file, take a look at
http://www.opennetcf.org/SourceBrows...InetPub/wwwroo
t/Source/OpenNETCF.Data/CSV/CSVDataAdapter.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...
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


Nov 16 '05 #6
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Wayne" <Me******@community.nospam> wrote in message
news:eL**************@TK2MSFTNGP10.phx.gbl...
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.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote
in message news:eV**************@TK2MSFTNGP10.phx.gbl...
Hi Wayne,

This is called a CSV file, take a look at

http://www.opennetcf.org/SourceBrows...InetPub/wwwroo
t/Source/OpenNETCF.Data/CSV/CSVDataAdapter.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...
>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
>
>



Nov 16 '05 #7
Gerry O'Brien <gk******@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
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.

--
Gerry O'Brien
Visual Basic.NET MVP
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Gerry O'Brien <gk******@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #9
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
Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Arne | last post by:
From: "Arne de Booij" <a_de_booij@hotmail.com> Subject: Comma delimited array into DB problems Date: 9. februar 2004 10:39 Hi, I have an asp page that takes input from a form on the previous...
4
by: Christine Forber | last post by:
I wonder if anyone knows of some javascript code to check a comma-delimited list of email addresses for basic formating. What I'm looking for is the javascript code to check a form field on form...
2
by: A E | last post by:
Hi, I was wondering if there was a function that handles list elements of a comma delimited list? I need to be able to pass values as a comma delimited list, count the number of values, and...
1
by: John B. Lorenz | last post by:
I'm attempting to write an input routine that reads from a comma delimited file. I need to read in one record at a time, assign each field to a field array and then continue with my normal...
2
by: Kenneth Koski | last post by:
Hello All, I have a comma delimited text file, which I would like to move into a SQL 2000 table . I created a DTS package in SQL Server and saved it as a VB.bas . I am writting the code in C#...
5
by: Yama | last post by:
Hi, I am looking to create a report comma delimited on a click of a button. Explanantion: 1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'" 2. Use either DataReader or...
9
by: Bernie Yaeger | last post by:
Is there a way to convert or copy a .xml file to a comma delimited text file using vb .net? Thanks for any help. Bernie Yaeger
5
by: SMOlesen | last post by:
Hi I need to split a comma delimited text, however if the comma is between ' ' then no split should occur ie: Class.Value, 'true' , 'some text', 'false', 'text, text, text' should split...
4
by: JustSomeGuy | last post by:
Hi. I have a comma delimited text file that I want to parse. I was going to use fscanf from the C library but as my app is written in C++ I thought I'd use the std io stream library... My Text...
2
by: Ron | last post by:
so if my textbox is named textbox1 and my listbox is named ltsdisplay, for the button that would make this all happen I would just need to: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.