WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

FileWrite and CRLF Character and End of Each Line

Keywords:     carriage return line feed

Question:

I encounter a problem dealing with file handling.

I have read the section on File read Parse and it mentioned about using ItemExtract or StrSub function to get line data. What I was trying to do is read a line of data from one file and then based on some conditions and write that data line to another 2 files.

It writes fine except that on one file it always has an extra blank line after each data line that I write. It seems to me that when the line is parsed, there is an end of line character at the end of each line and FileWrite will put the actual data on one line and then put the end of line charater on the second line for all the data lines in the file.

I tried to use the ItemExtract and StrSub function to just get the data out of the file and just write the data line but it didn't work. So I'm wondering if there is any other way to skip the new line character on the file that I want to write.

Answer:

  1. FileWrite adds a CRLF to the end of every line you write (This is a free public service - no charge or additional fees apply)

  2. It appears that some kind of line end character is getting picked up during the variable parsing process. Its probably A LF character.

  3. If you right click the output file with the extra lines in it, then select the "Open With..." (the one that is NOT on top) and select BROWSER, and then under Browser options select Hex Dump, you can see the characters written. a CR looks like a 0d a LF is a 0a

    This information would be helpful.

  4. just prior to the FileWrite you may be able to clear out the offending stuff as follows:
    line="stuff you want to write to the file")
    line=StrReplace(line,@LF,"")
    line=StrReplace(line,@CR,"")
    FileWrite(handle,line)
    
  5. If you can narrow down the point there the line termination characters enter your data stream, it is more efficient to get rid of them early on, perpahs immediately after an ItemSelect.
    var=ItemSelect(xx,mydata,@tab)
    var=StrReplace(var,@LF,"")
    
    line=strcat(xxx,var,yyy)
    FileWrite(handle,line)
    

    Article ID:   W13079
    
    Filename:   FileWrite and CRLF Character.txt
    File Created: 1999:04:15:16:51:36
    Last Updated: 1999:04:15:16:51:36