Silly Writeline Question

volboy04

New member
Joined
Jul 16, 2008
Messages
4
Programming Experience
3-5
I'm new to VB (I'm a SAS and C++ programmer that learned VB recently) and writing a program to export numerical data to a .csv file. I have been using System.IO.writeline(string) to write to the file - the numerical data is being manipulated in string form.
My problem is this- after the 28th character, the exported data wraps to the next line. So, instead of output that looks like this:
7,16,+3.54,+2.36,+2.28,3.932,1.345

I get output in the file that looks like this:
7,16,+3.54,+2.36,+2.28,3.932
,1.345

Since I'll be reading this .csv file into SAS, this is terribly problematic.

The relevant code lines look like this...

VB.NET:
        Dim data_outfile As System.IO.File
        Dim output_write As System.IO.StreamWriter
        output_write =  data_outfile.CreateText("C:\...\Data.txt")

...

        output_write.WriteLine(Output_Data)
        output_write.Close()

Where Output_Data is the string.

Thank you very much in advance for any help.
 
Last edited by a moderator:
output_data MUST contain a LF or CRLF at position 28 then. If you assert that it does not, then please tell me how you came to this conclusion
 
The particular string in Output_Data is given in my post above (my apologies for not more clearly identifying it).

Forgive me, but I am unsure what you mean by LF or CRLF. My writeline(output_data) result in the .csv file is exactly this:

7,17,+1.26,+1.22,+0.42,3.967
,1.36

though Output_Data is constructed from data pulled from the web (specifically, from Yahoo finance, see below).



HOWEVER, I just noticed that if I straightforwardly define Output_Data this way:

Output_Data = "7,17,+1.26,+1.22,+0.42,3.967,1.36" , my problem goes away!

So, you must be right. I must have the characters you refer to somehow in the string I am constructing...would you mind defining LF or CRLF?

Again, thank you. This has been very helpful.

...EDIT...

GOT IT. Thank you, I just trimmed some of the strings I was scraping from the internet to get rid of the characters you referred to. Thank you VERY much for the help.
 
Last edited:
LF = a line feed
CRLF = a carriagereturn linefeed pair

to remove them from the string:

Dim newStr as String = Regex.Replace(oldStr, "[\r\n]", "")
 

Latest posts

Back
Top