Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

RegEx CSV

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RobKaratzas - 06 Dec 2004 13:17 GMT
hi folks

I went thru some major pains with SQL Srvr trying to import a CSV greater
than 255 columns (limitation with MS TXT/CSV  driver) and had to write my
own sp_OA file reader, parsing routines (views), etc..

I'm down to one last issue. I need to get:

 '(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)'

to replace the first character on the split, IF IT's a COMMA with a '|'
(adding to the expression above).

Expresso testing seems to indicate everything is a go as far as the
expression goes, but I need this enhancement (to take care of embedded
commas in cells).

Expresso input:

37,"'AB","'CDE","'FG","'( (4.0L 4X2,4X4 AT L/OIL
COOLER)",NE01,"'030002","'001",,,,,W,XAGP5695,*,0,0,1,1,1,1,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,X,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,
Here's the TSQL code:
====================
DECLARE @rownum int
 DECLARE @rowtext varchar(8000)
 DECLARE @xstring varchar(8000)
 DECLARE @xpos SMALLINT
 DECLARE @xcount SMALLINT
 DECLARE @xlenString SMALLINT
 DECLARE @sDelim varchar(5)
 DECLARE @eDelim varchar(5)
 DECLARE @regex integer

 set @sDelim = char(44)+char(39)+char(34) --[,'"]
 --print @sDelim
 --set @eDelim = char(34)+char(39)+char(44) --["',]
 --print @eDelim
 SET @regex = dbo.regexObj( '(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)', 0, 1 );

 --DECLARE a1159_Cursor CURSOR FAST_FORWARD FOR SELECT rownum,rowtext from
VIEW_1159Step2 where rownum<85085 ORDER BY rownum
 DECLARE a1159_Cursor CURSOR FAST_FORWARD FOR SELECT rownum,rowtext from
VIEW_1159Step2 ORDER BY rownum
 OPEN a1159_cursor FETCH NEXT FROM a1159_cursor INTO @rownum,@rowtext

 WHILE @@FETCH_STATUS = 0
 BEGIN
-- double quote checker
        If dbo.cnt_strings(@sDelim,@rowtext)>0
BEGIN
            SET @xstring= dbo.regexObjReplace( @regex, @rowtext, '' )
    PRINT
CONVERT(varchar(10),@rownum)+replace(@xstring,char(39),'')+char(44)
END
ELSE
    PRINT
CONVERT(varchar(10),@rownum)+char(124)+replace(@rowtext,char(44),char(124))+
char(124)
    FETCH NEXT FROM a1159_cursor INTO @rownum,@rowtext
 END
--delete from tmp1159
 CLOSE a1159_cursor
 DEALLOCATE a1159_cursor
==============
thanks
Rob
RobKaratzas - 06 Dec 2004 13:23 GMT
SORRY, THIS WAS A REPOST.

submittal for both posts reported an operations error (and I didn't think
either made it)

rob

>  hi folks
>
[quoted text clipped - 62 lines]
>  thanks
>  Rob

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.