file manipulation

i need to take the trailing empty line from a text file...how do i do this?

also, how do you write to a text file without writing an end of line character?
SeshAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
macuConnect With a Mentor Commented:
Using the ; allows you to write something to a file and not move to a new line, so that more data can be added on the same line. It does work, very simple!
0
 
paulstampCommented:
Tried using the Trim$ function to remove blanks ?
0
 
rovermCommented:
Tried the Open statement yet ?

Open "inputfile" For Input As #1
Open "outputfile" For Output As #2

Input #1, strReadLine
'do some stuff
Print #2, strReadLine

Close #1
Close #2

When you read the input file you won't see the end-of-line char !

Good luck !

RoverM
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
SeshAuthor Commented:
my problem actually arises from the inability to output a line without it creating an eoln at the end.

for example,
print %1,"hello"

would make the file like so:
--------beginning of file--------
hello(EOLN)
(EOF)
-----------end of file-------------

but i want it to read:
--------beginning of file--------
hello(EOF)
-----------end of file-------------
0
 
rovermCommented:
If you are writing AND reading the file why don't you add an 'END-CHAR' ?
When you read it again, YOU know that you can ignore the last character !

Another way: Instead of writing blanks (spaces) why don't you write Chr(0) a couple of times ?

RoverM
0
 
macuCommented:
Just do:

Open "FileName" For Output As #X
Print #X, "Data";

The ; is the important part.
0
 
MicheltCommented:
Have You tried to open the File as Binary, then read through the String to remove all the EOF Characters !
and Save it to a New File !


0
 
nico5038Commented:
Sesh,

A DOS-text file contains normally two bytes to indicate the end of a line:
CarriageReturn and LineFeed. (CR / LF)
With the print statement these are inserted automatically.
When a file only contains LF's (normal for UNIX) it's seen by Notepad as one long string, however Wordpad shows it on different lines!.

To create a file yourself with control about the endofline character(s) you should follow Michelt advice to open the file as Binary and write the full lines with a concatenated vbCRLF variable at the end and "forget it" for the last one.

0
 
SeshAuthor Commented:
hmmm... interesting..

does that:
print #X, data ;  take off the cr/lf from the print?? i havent got the dev studio at this moment (not at home at the moment), so cant test it...

i ended up doing a byte - by - byte get() and put() and testing for multiple eoln s, but would much rather use that print thingy
0
 
SeshAuthor Commented:
ill take your word on it... thanx a lot!
0
 
macuCommented:
No problem.
0
 
nico5038Commented:
Sesh,

It does not take off the CR/LF, but it prevents the placement of it, as the ";" means 'more information has to be added to this string'
The only disadvantage can be that you end up with a string that's too long!
(Check the max string length of your VB version)
That's also why I advised to use the binary file type. Thus no length limit will appear!
0
All Courses

From novice to tech pro — start learning today.