LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default How to parse a csv string with text qualifiers

The Split function is very nice, but it does have limited
functionality. The strings I'm trying to split often have
text qualifiers in them. I've tried searching previous
posts in both Excel and Access and have found several
alternatives, but they all break if the qualifier is also
part of the text. Let me give an example.

I create a .csv file in notepad that contains the
following:
1 inch,"2""","3 inches","4, 5, and 6""",7 inches,"8, 9,
and 10 inches",11 inches

If I then open that csv file in Excel, everything is very
nicely split up into cells A1 through G1:
1 inch
2"
3 inches
4, 5, and 6"
7 inches
8, 9, and 10 inches
11 inches

Now let's say I write a code to programmatically read the
csv file into vba using:
Open strInfFile For Input Access Read As intFileNum
Line Input #intFileNum, strInputString

debug.print strInputString
gives the following result:
1 inch,"2""","3 inches","4, 5, and 6""",7 inches,"8, 9,
and 10 inches",11 inches

What I'd like to do is take that string and break it up
into a one-dimensional array with the same contents as the
cells in Excel.

But I keep getting things like:
1 inch
"2"""
"3 inches"
"4
5
and 6"""
7 inches
"8
9
and 10 inches"
11 inches

or

1 inch
"2"""
"3 inches"
"4, 5, and 6"""
7 inches
"8, 9, and 10 inches"
11 inches

or

1 inch

3 inches

7 inches
8, 9, and 10 inches
11 inches

Help!!! Isn't there a decent csv string parser anywhere?
I'm using Excel 2000.
I've thought about writing something myself, but I'm
afraid I can't figure out how to handle the text
qualifiers either.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
parse text string Dave F[_2_] Excel Worksheet Functions 4 April 29th 07 07:48 AM
Parse this string David Excel Discussion (Misc queries) 2 February 20th 07 04:57 AM
Q: parse string JIM.H. Excel Discussion (Misc queries) 3 October 22nd 05 01:45 AM
String Parse J Excel Programming 3 August 10th 04 10:27 PM
Wish to parse through a text string to find data Neil Bhandar[_2_] Excel Programming 2 October 24th 03 07:04 PM


All times are GMT +1. The time now is 11:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"