QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: IronMan on March 24, 2020, 03:10:49 pm
-
Does anyone know how to limit the width pf a plain text file to allow 65 characters max per line?
I am reading a text file, and once I Print # it back to a text file after making changes to it, the lines are too long and it don't wrap to the next line but instead the lines inside are very long in width. Perhaps a way to do word wrap?
I'm open a file and modifying it to remove "." at the front of each line, and to put a space in between each day.
Example:
CLS
OPEN "forecast.txt" FOR INPUT AS #1
OPEN "test.txt" FOR OUTPUT AS #2
WHILE NOT EOF(1)
INPUT #1, LineTxt
IF LEFT$(LineTxt, 1) = "." THEN
PRINT CHR$(13); CHR$(13)
PRINT #2, CHR$(13); CHR$(13)
PRINT MID$(LineTxt, 2); " ";
PRINT #2, MID$(LineTxt, 2); " ";
ELSE
PRINT #2, LineTxt; 'write output to new file test.txt
PRINT LineTxt; 'prints output to screen
END IF
WEND
CLOSE #1
CLOSE #2
The problem is, It open the file for input and make the changes, but when the output changes a written to the new file test.txt, the lines for each line are too long. I need to limit them to no more than 65 characters per line for what I'm needing to do. I have tried several thing using the col% and LEFT$ but can't get it to use no more than 65 characters per line before starting a new line.
I am attaching the text file for reference.
If anyone know how to resolve this please share any ideas you may have.
Any help is appreciated.
Thank you.
Kent
[ This attachment cannot be displayed inline in 'Print Page' view ]
[ This attachment cannot be displayed inline in 'Print Page' view ]
-
You know the lines already look OK in forecast.txt maybe wordwrap isn't needed, try this:
PRINT #2, lineTxt
'write output to new file test.txt PRINT lineTxt;
'prints output to screen
-
You know the lines already look OK in forecast.txt maybe wordwrap isn't needed, try this:
PRINT #2, lineTxt
'write output to new file test.txt PRINT lineTxt;
'prints output to screen
Yes, By removing the ; WordWrap from the #2 does put it in the correct spacing from left to right as needed.
However, the first three entries OVERNIGHT..., TUESDAY..., and TUESDAY NIGHT... do not format correctly and adds additional lines. The rest of the days in the file looks fine. I think it because the first three days have more lines of text.
But yes, bplus, you are correct and that fixes it. Just bring on another thing to have to figure out now to get the first three days to look right.
Thanks for your help.
- Kent
-
As a word of encouragement, if you can get it looking right on screen, you should be able to duplicate it in the file, PRINT and PRINT #2 work about the same. CHR$(13) is carriage return (on type writer) starts line at beginning, CHR$(10) is line feed, starts new line, together they start at beginning of next line. Some .txt editors just use one or other. CHR$(9) is a tab that might come in handy.