ASP - Remove blank lines - Asked By john mathew on 18-Jul-14 12:35 PM

 I wanted to know how do I remove blank lines from text file. Any help will be appreciated.

Look for Chr... - Asked By Robbe Morris on 24-Apr-01 08:18 AM

Here are a few examples of how to remove special characters
 in strings.  The first one ought to do the trick.

 replace(sString,vbcrlf,"")
 replace(sString,Chr(13),"")
 replace(sString,Chr(10),"")

remove blank lines - Asked By raghavendra reddy on 24-Apr-01 09:22 AM

I have already tried with that but it was of no use. Any other way to do it.

Hmmm... - Asked By Robbe Morris on 24-Apr-01 09:48 AM

Chances are your text file is using another control character to signify an end of line or new line.  Chr(13),Chr(10) combinations are the most common but some systems use others.

You'll probably have to write a little program to evaluate the ASC() code of each character in the file.  Make the loop stop on characters outside the range of alphabetical or punctuation characters.  This help you identify which character to perform the replace on.

I've seen this problem the most when working with files brought over to windows from UNIX machines.

But, my previous reply works in most cases.
Remove blank lines - Asked By raghavendra reddy on 18-Jul-14 12:35 PM
I tried with that also. You know a strage thing is happening. When I do asc() it wont show asc code for blank lines at all. Would you like to have a look at my txt file.
Ok. - Asked By Robbe Morris on 24-Apr-01 02:11 PM
Email it to info@eggheadcafe.com
Here's the code that works with your test file. - Asked By Robbe Morris on 24-Apr-01 03:29 PM
Here's the asp and yes it works fine.

 <
      Dim oFS  
      Dim oFSTxt
      Dim sString  
     
      Set oFS = Server.CreateObject("Scripting.FileSystemObject")
      Set oFSTxt = oFS.OpenTextFile("c:\inetpub\wwwroot\test.txt")
      sString = oFSTxt.ReadAll
      Set oFS = Nothing
     
     sString = Trim(sString)
     sString = Replace(sString, Chr(13), "")
     sString = Replace(sString, Chr(10), "")
    
     response.write sString

     on error resume next

     Set oFSTxt = nothing
     Set oFS = nothing
 %>