Can anyone take a look at this and tell me why, when given a string and a specified width for word wrapping, it sometimes trims the string way too short, or 3 or 4 characters too long? I've been frying my brain with this and I just can't get it straightened out:
this.FitMsg=function(text)
{
Can anyone take a look at this and tell me why, when given a string and a specified width for word wrapping, it sometimes trims the string way too short, or 3 or 4 characters too long? I've been frying my brain with this and I just can't get it straightened out:
Re: fried brain
By: X V Lxxix to All on Fri May 09 2008 10:54 am
Can anyone take a look at this and tell me why, when given a string and a specified width for word wrapping, it sometimes trims the string way too short, or 3 or 4 characters too long? I've been frying my brain with this and I just can't get it straightened out:
Have you looked at the word_wrap() global function?
Have you looked at the word_wrap() global function?
yes.. it wraps to a new line on the left side. I needed to make something that wraps within a specified "window" on the screen. I'm pretty sure it does that anyway. I'm actually checking it right now
Re: fried brain
By: MCMLXXIX to Deuce on Fri May 09 2008 11:20 pm
Have you looked at the word_wrap() global function?
yes.. it wraps to a new line on the left side. I needed to make something that wraps within a specified "window" on the screen. I'm pretty sure it does that anyway. I'm actually checking it right now
You can pass in the width as an argument. :-)
You can pass in the width as an argument. :-)
Yeah, but it still wraps to the left side of the screen. I need it wrap
away from the left side. Unless I'm just not doing it right... that is always a possibility when it comes to me.
Re: fried brain
By: MCMLXXIX to Deuce on Sun May 11 2008 05:35 pm
You can pass in the width as an argument. :-)
Yeah, but it still wraps to the left side of the screen. I need it wrap away from the left side. Unless I'm just not doing it right... that is always a possibility when it comes to me.
I'm sure I misunderstand the question. The word_wrap() function doesn't do anything with the screen.
string="kljhsadflkhasfdjkhasdflhsadlfjhsadfjhsdlfhaslfdhsadflsdaflhasdfljkh "; console.gotoxy(10,1); //move to the first row, 10 spaces from the left edge
console.putmsg(word_wrap(string,10));
Re: fried brain
By: MCMLXXIX to Deuce on Mon May 12 2008 04:30 pm
string="kljhsadflkhasfdjkhasdflhsadlfjhsadfjhsdlfhaslfdhsadflsdaflhasdfl "; console.gotoxy(10,1); //move to the first row, 10 spaces from the left edge
console.putmsg(word_wrap(string,10));
Ah...
console.putmsg(word_wrap(string, 10).replace(/\n/,"\n "));
console.putmsg(word_wrap(string, 10).replace(/\n/,"\n "));
that would work, sort of... but the idea is to make the text wrap within a window at either a menu, or in the midst of another script, so having preceeding spaces would mess up the surrounding graphics. the distance from the left will also be supplied as a variable and will change depending on what's going on..
you should make word_wrap take a starting_column argument! .... :)
you should make word_wrap take a starting_column argument! .... :)
The word wrap function is in now way connected to output... so a starting_column argument is pointless.
Re: fried brain
By: MCMLXXIX to Deuce on Mon May 12 2008 06:10 pm
console.putmsg(word_wrap(string, 10).replace(/\n/,"\n "));
that would work, sort of... but the idea is to make the text wrap within window at either a menu, or in the midst of another script, so having preceeding spaces would mess up the surrounding graphics. the distance fr the left will also be supplied as a variable and will change depending on what's going on..
Ok...
console.putmsg(word_wrap(string, 10).replace(/\n/,"\n\1"+ascii(127+10)));
you should make word_wrap take a starting_column argument! .... :)
The word wrap function is in now way connected to output... so a starting_column argument is pointless.
Regarding windows, they aren't supported natively. You could do this functionality using the graphic.js library though:
load("graphic.js");
var window=new Graphic(10,24);
window.putmsg(word_wrap(1,1,string, window.width));
window.draw(1, 10);
You could split() the word_wrap()ed result on /\n/ and process the
returned array elements individually, to place them in the "window". Where is word_wrap() implemented? Could it be altered to optionally return an array type?
I actually had no idea that could be done with Graphic.js, but it didn't seem to work when I tested it anyway. What does word_wrap do? put an \r\n
in the supplied string at the supplied width?
Re: fried brain
By: MCMLXXIX to Deuce on Mon May 12 2008 11:10 pm
I actually had no idea that could be done with Graphic.js, but it didn't seem to work when I tested it anyway. What does word_wrap do? put an \r\n in the supplied string at the supplied width?
word_wrap() splits a string of text into multiple lines on word boundaries s that no line is longer than the specified width. It will not place a newlin in the middle of a word unless that word is longer than the line width.
Where is word_wrap() implemented? Could it be altered to optionally return an array type?
It's implemented in js_global.c. It could return an array, but if you want array, just do a .split(/[\r\n]+/) or something. That way you get to use co string methods and I don't have to do anything. :-)
Sysop: | Ree |
---|---|
Location: | Toronto, ON |
Users: | 2 |
Nodes: | 10 (0 / 10) |
Uptime: | 102:05:19 |
Calls: | 373 |
Files: | 2 |
Messages: | 38,870 |