×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Reading a text file - LF vs CRLF

Reading a text file - LF vs CRLF

Reading a text file - LF vs CRLF

(OP)
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?

RE: Reading a text file - LF vs CRLF

After loading the string into Text variable, you can get an array of rows with:
v = Split(Text, vbCrLf)

combo

RE: Reading a text file - LF vs CRLF

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

CODE

sLine = Replace(sLine, vbLf, "something") 

RE: Reading a text file - LF vs CRLF

(OP)
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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close