• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 870
  • Last Modified:

How do I remove hidden Line breaks in a text file with vbscript?

I am using a vbscript to read the event log and dump the information into a text file. I will be importing the text file at a later date into Excel or elsewhere.

the important bits of code is  below, however it doesnt appear to be working. The below gets rid of the majority of line breaks but still leaves some behind and it shows in Notepad as a little square (see attached image) but when looked at through notepad++ or excel it does as below and uses a new line
"The memory could not be "read"
Click on OK to terminate the program"

Is there any way to get rid of these line breaks, where have I gone wrong in my code?

Details = objevent.message
Details = Replace(Details,vbCrLf,"")
strFile.WriteLine Details

Open in new window

Image1.jpg
0
scarthy
Asked:
scarthy
  • 3
  • 2
1 Solution
 
bluntTonyCommented:
Try replacing the ANSI character for carriage return, e.g.
Details = Replace(Details,CHR(13),"")
0
 
TakedaTCommented:
A vbCrLf is the equivilant of a chr(13)&chr(10) which is also the same as a carriage return and line feed.  When you view thes on a windows pc, unless you have both of those characters consecutively and in that order, notepad and other text editors will not show them as seperate lines and will show whichever character is there as the square that you see.  If you want to see what these characters really are, you can check by opening the text file in a hex editor and see what their value is.

If you want to get rid of ALL of these characters.  Then along with what bluntTony said,

Details = Replace(Replace(Details,CHR(13),"") ,CHR(10),"")
0
 
scarthyAuthor Commented:
Thanks very much to you both for your replies.
bluntTony I tried yours first, but unfortunately I got the same result and also got extra rows between each result (probably because of the missing chr(10) value. But thanks again for replying.

TakedaT. Thats worked thank you very much.  How does yours work? does it replace  all carriage returns with line feeds and then replace all line feeds with a space?

Thanks again both of you for your efforts.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
scarthyAuthor Commented:
Thanks
0
 
TakedaTCommented:
No problem.

If you break down the line from inside out.  It first replaces chr(13) with "", which is nothing so it deletes the character, then the next step outward does the same for any chr(10).  It gets rid of them one at a time.  Your original replace only looked for both of them as a whole (vbCrLf stands for just that, vb CarriageReturnLineFeed).  If yours didnt see a chr(13) and a chr(10) directly next to eachother, it left it alone, leaving some chr(10)s in there.

Details = Replace(Replace(Details,CHR(13),"") ,CHR(10),"")
0
 
scarthyAuthor Commented:
I understand. Thanks for that.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now