473,786 Members | 2,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextFieldParser problem with Double Quotes within Quotes

1 New Member
Hi, I'm basically trying to import a CSV into an ACCESS database. Sample date is shown below:

"",10173,"Devel opment Manager - Social Economy Sector","Trust Bank",10153,,"L olalll Pudd","Meet the requirements of Structured Finance & Relationship Teams for "transactio n support" at all times, ensuring appropriate analysis and clarity in respect of required/request","",09-Sep-2008,42000,3800 0,"+ LTA + bonus",,,,41000 ,45000,,,"","", ,"","","",,,"", ,"A","AUK,AUL,A UN,CBE,RBD"

The CSV data is malformed, as each field requires double quotes enclosed around them. Unfortunately, one of the fields contain double quotes within. So I'm trying to use the TextFieldParser to read the file and replace the double quotes with single quotes for that particular instance.

If I set the HasFieldsEnclos edInQuotes to True, an error is thrown at the line. If I use False the line is read, but the field data is spilt incorrectly.
Expand|Select|Wrap|Line Numbers
  1. Using csvFileReader As New TextFieldParser(App_Path() & csvFileFullPath)
  2.  
  3. csvFileReader.TextFieldType = FieldType.Delimited
  4.  
  5. csvFileReader.Delimiters = New String() {","}
  6.  
  7. 'csvFileReader.HasFieldsEnclosedInQuotes = True
  8.  
  9. csvFileReader.HasFieldsEnclosedInQuotes = False
  10.  
  11. csvFileReader.TrimWhiteSpace = True
  12.  
  13. Dim currentRow As String()
  14.  
  15. While Not csvFileReader.EndOfData
  16.  
  17. Try
  18.  
  19. Dim i As Int32 = 1
  20.  
  21. Dim outputRow As New Text.StringBuilder()
  22.  
  23. currentRow = csvFileReader.ReadFields()
  24.  
  25. For Each currentField As String In currentRow
  26.  
  27.     currentField = currentField.Replace(Chr(34), Chr(39)) 'replace double quote with single quote if needed
  28.  
  29.     OutputRow.Append(currentField)
  30.  
  31.     If i < currentRow.Length Then
  32.  
  33.         outputRow.Append(Chr(9)) 'add a tab for each field except last one
  34.  
  35.     End If
  36.  
  37.     i = i + 1
  38.  
  39. Next
  40.  
  41. Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
  42.  
  43.     TextBox1.Text = ex.ToString
  44.  
  45. End Try
  46.  
  47. End While
  48.  
Please can someone help, as I'm sure this type of issue with importing CSV files is a problem for many developers.
Oct 30 '08 #1
1 4925
Stang02GT
1,208 Recognized Expert Top Contributor
Please make sure you are using code tags.



Moved to Misc.
Oct 30 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
4231
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link, which when you click it bookmarks the site (much easier). The favicon is never saved if the site is bookmarked this way. Does anyone have any ideas how to fix this?? This is the code: <script language="JavaScript">
4
2829
by: Dennis M. Marks | last post by:
I generate a SELECT list dynamically by taking items from a table. I have DOCUMENT.WRITE statements that write a combination of literals and variables including < and > characters. The HTML seems to work all right but validators show errors of having a closing > without an opening <. Even though these are in DOCUMENT.WRITE statements within quotes they are still flagged as errors. Is there any way around this. I have tried HTML entities...
7
2448
by: Chris | last post by:
<< Translation in english of my main post >> Hi, I do not success to pass by parameter the contents of "param". in the function "Main" if I replace Suite('+param+') by Suite('+40+') dans la fonction Main si je remplace Suite('+param+') par Suite('+40+') then all is ok. For info, the parameter "param" will be a string Thanks for your help
3
3170
by: Stefania Scott | last post by:
How do I resolve the problem of passing a string that has quotes within in a SQL statement? Sometimes the string contains a single quote (') and some others it contains the double quote (")? Any clue... Thank you, Stefania
2
1723
by: sparks | last post by:
ok I was trying to do something real simple I thought Me.Clinic.DefaultValue = Me.Clinic.Value I got error either ! or . misused or not found...something like that I thought ok how can you not find the variable that this field is tied to. ok it takes a variant so maybe its Me.Clinic.DefaultValue = Me..Value no thats not it so I just tried everything then someone said no do
17
2794
by: Mark | last post by:
I must create a routine that finds tokens in small, arbitrary VB code snippets. For example, it might have to find all occurrences of {Formula} I was thinking that using regular expressions might be a neat way to solve this, but I am new to them. Can anyone give me a hint here? The catch is, it must only find tokens that are not quoted and not commented; examples follow
3
6732
by: al jones | last post by:
I’m using textfieldparser to read a data file. which contains, for example: Amondó Szegi Amondo Szegi andré nossek André Nossek © Characte Character Note the vowels with diacriticals and the copyright symbol - it is dropping these (and other similar) characters which fall outside ascii range (apparently)
2
1508
by: nargish | last post by:
I am eager to replace double quotations in the output that is being displayed. input text : This is "within quotes" output text: This is <p class="quotes">within quotes</p> I have worked out something like this $text = ereg_replace(' "+"',"<p class=\"quotes\">\\0</a>", $str); But i dont feel that its really good enough as the quotes still remain.Any suggestions will be very helpful.
12
3489
by: tom_kuehnert | last post by:
Hi! I'm trying to execute a program using system(). The program itself is located in some path which might contain whitespaces. Simple solution would be this: system("\"C:\A B\C.exe\""); but now this program also has parameters which need to be passed (again with paths containing whitepaces)
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.