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(Mea sDataFileN ame, True)
For j = 0 To maxAinIx - 2
objWriter.Write(AinUnit(j, UnitsEMU))
objWriter.Write(",")
Next
objWriter.WriteLine(AinUni t(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
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(Mea
For j = 0 To maxAinIx - 2
objWriter.Write(AinUnit(j,
objWriter.Write(",")
Next
objWriter.WriteLine(AinUni
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The replace function won't do anything if there are no quotes in the results...did you try the code?
ASKER
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.
Thank you for your help. Perhaps I will get a chance to revisit this issue again.
-saige-