Link to home
Start Free TrialLog in
Avatar of charlieb01
charlieb01

asked on

VB.Net - Writing Strings to a comma delimited file

I am attempting to write data out to a comma delimited file using a For - Next loop.
Some of the strings in the array use a double quote ( " ) as you would use to indicate Inches. The first few elements of the array do not have the double quote and they work fine, however, once I reach an element that contains the double quote the code treats it differently and I end up with a long string that does not handle the comma as a delimiter.

Here is the code:
Dim objWriter As New System.IO.StreamWriter(MeasDataFileName, True)

For j = 0 To maxAinIx - 2
    objWriter.Write(AinUnit(j, UnitsEMU))
    objWriter.Write(",")
Next
objWriter.WriteLine(AinUnit(j, UnitsEMU))

objWriter.Close()


I need help to ensure that the code will treat each element as a separate entry and no have the double quotes mess up the output.

Thanks,
Charlie
Avatar of it_saige
it_saige
Flag of United States of America image

What does the code for your AinUnit look like.  This is most likely what you want to change so that it can properly handle double-quotes.

-saige-
SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of charlieb01
charlieb01

ASKER

The values in the AinUnit array come from a database. Some of them use the degrees symbol (for temperature), some use the double quotes (for inches - as in barometric pressure: "Hg) and some don't use any special symbol (such as the letter W  for watts). So I don't know how I can replace just the double quotes because it only affects some of the values.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The replace function won't do anything if there are no quotes in the results...did you try the code?
The replace function did not work and I have run out of time to solve this problem. So, I am re-writing the database fields to use 'in' (for inches) to replace the double quotes.

Thank you for your help. Perhaps I will get a chance to revisit this issue again.