
-----------------------------------
viper012289
Sun Feb 19, 2006 3:32 pm

help with text
-----------------------------------
hey i was wondering how i would centre text in file. i managed to get the text centred into the run window but when i check the text file its still aligned right...help would be appreciated

var streamnumber : int
var streamnumber2 : int
var words : string
var i : int

open : streamnumber, "text.txt", get
open : streamnumber2, "centre.txt", put
i := 1
loop
    get : streamnumber, words : *
    put : streamnumber2, words
    locate (i, maxcol div 2 - length (words) div 2)
    put words
    i := i + 1
    exit when eof (streamnumber)
end loop
close : streamnumber2

-----------------------------------
Cervantes
Sun Feb 19, 2006 3:43 pm


-----------------------------------
Since a file doesn't have a "maxcol", the best thing you could do is go through all the lines and find the longest line.  Set things so that this line will, when everything is "centred", just touch the left margin (ie. don't add spaces to this line).  To "centre" other lines, pad them with spaces.

-----------------------------------
viper012289
Sun Feb 19, 2006 4:05 pm


-----------------------------------
how exactly would i go about doing that.

-----------------------------------
Cervantes
Sun Feb 19, 2006 4:22 pm


-----------------------------------
You'll learn more if you do it yourself than if someone tells you the answer.  Give it a try.

You may find the [url=http://www.compsci.ca/v2/viewtopic.php?t=8229]String Manipulation Tutorial of help.

-----------------------------------
viper012289
Sun Feb 19, 2006 4:33 pm


-----------------------------------
i managed to calculate how much i will be spacing by counting the characters in each line and then subracting it from the largest line in my case 70....but i'm not sure how to place it in the put line with the file...

-----------------------------------
Cervantes
Sun Feb 19, 2006 4:38 pm


-----------------------------------
but i'm not sure how to place it in the put line with the file...

put : fileNo, repeat (" ", num_of_spaces) + line


-----------------------------------
viper012289
Sun Feb 19, 2006 4:51 pm


-----------------------------------
thanks so much it worked like a charm....only one question....sometimes when centreing  the number of spaces technically is supposed to be 2.5 
so my question is does it actually space 2.5 from the edge or does it just round and go to 3?

-----------------------------------
Cervantes
Sun Feb 19, 2006 5:01 pm


-----------------------------------
It would put 2 or 3 spaces.  Unless your font has a "half a space" character, it's impossible to have half a space.  If you're using a monospaced font, it's impossible.

-----------------------------------
sylvester-27
Mon Feb 20, 2006 8:43 am


-----------------------------------
just for reference, use code tags when posting code
