Author |
Message |
viper012289
|
Posted: Sun Feb 19, 2006 3:32 pm Post subject: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sun Feb 19, 2006 3:43 pm Post subject: (No subject) |
|
|
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. |
|
|
|
|
![](images/spacer.gif) |
viper012289
|
Posted: Sun Feb 19, 2006 4:05 pm Post subject: (No subject) |
|
|
how exactly would i go about doing that. |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sun Feb 19, 2006 4:22 pm Post subject: (No subject) |
|
|
You'll learn more if you do it yourself than if someone tells you the answer. Give it a try.
You may find the String Manipulation Tutorial of help. |
|
|
|
|
![](images/spacer.gif) |
viper012289
|
Posted: Sun Feb 19, 2006 4:33 pm Post subject: (No subject) |
|
|
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... |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sun Feb 19, 2006 4:38 pm Post subject: (No subject) |
|
|
viper012289 wrote: but i'm not sure how to place it in the put line with the file...
code: |
put : fileNo, repeat (" ", num_of_spaces) + line
|
|
|
|
|
|
![](images/spacer.gif) |
viper012289
|
Posted: Sun Feb 19, 2006 4:51 pm Post subject: (No subject) |
|
|
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? |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sun Feb 19, 2006 5:01 pm Post subject: (No subject) |
|
|
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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
sylvester-27
![](http://www.icejerseys.com/images/vintage_collection/toronto_st_pats/heritage_jersey.jpg)
|
Posted: Mon Feb 20, 2006 8:43 am Post subject: (No subject) |
|
|
just for reference, use code tags when posting code |
|
|
|
|
![](images/spacer.gif) |
|