WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 string, tom, November 16, 2004
     Re:string , Dave, November 21, 2004
     Re:string, Avner, November 17, 2004
         Re:string, tom, November 17, 2004

Subject: Re:string From: tom Date: November 17, 2004

Thank you for the help Avner...Though I modified your code and this is the final function (if anyone is intrested)...

var sSpace = '';
for (i=0; i<255; i++) {
  sSpace += ' ' ;
}

function m(str, len) {
 
return (str + sSpace).substring(0, len);
}

/tom

From: Avner
Sent: November 17, 2004
Subject: Re:string

How about :

 

var iMAX = 255;
var sSpace = new Array();
for (var i=0;i<iMAX;i++)
 {
  sSpace[i] = " " ;
 }
sSpace = sSpace.join("");


function m(str, len)
{
var sTemp =  str + sSpace;
return sTemp.substring(0,len);
}

alert("[" + m('tom', 10) + "]");      // returns 'tom       '

From: tom
Sent: November 16, 2004
Subject: Re:string

Does anybody know a way to return strings with different lengths to same length. For now I use this function but aren't happy with it.

function m(str, len) {
  b = '';
 
for (q=0; q<(len-str.length); q++) {
    b += ' ';
  }
 
return str + b;
}

m('tom', 10);      // returns 'tom       '
m('lisa', 10);     // returns 'lisa      '
m('michael', 10);  // returns 'michael   '
m('peter', 10);    // returns 'peter     '

thanx for any help
/tom






Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX