Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a text file - LF vs CRLF

Status
Not open for further replies.

reidarjorgensen

IS-IT--Management
Apr 14, 2004
2
AU
I am reading a comma-delimited file that was exported from Excel. One of the columns has embedded Line Feeds (x'0a'), and when I read it in with VBScript, the text in that column is, naturally, broken into separate lines where the Line Feed character is.

The end of the record has, as you'd expect, a CRLF - x'0d0a'.

So my question: Is there a way to read a line of text, recognising the CRLF, but ignoring the lone LF? I want the entire record, which started life as a row in a spreadsheet, to be read as a single record, not broken up.

When I open the file in Notepad, it ignores the LF (It's still there, as a little square character, but the line is not broken.). Is there some nifty VBscript option or method that can do this?
 
After loading the string into [tt]Text[/tt] variable, you can get an array of rows with:
[tt]v = Split(Text, vbCrLf)[/tt]

combo
 
Use the Replace function to replace it with something else, or nothing at all

Code:
sLine = Replace(sLine, vbLf, "something")
 
Thanks combo and Gitarzan, I ended up having to use both your suggestions.

I used ReadAll to read the entire file in as one long string.

Replacing the vbLF affected the vbCRLF as well, which resulted in no end-of-line markers at all, so first I Replaced all vbCRLF with a random string ("&Hfedc" - not likely to be found anywhere), then Replaced vbLF with a space, then used Split with &Hfedc as the delimiter.

Problem solved!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top