A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: is there an LPAD or RPAD function in ActionScript?

  1. #1
    Senior Member
    Join Date
    Mar 2002
    Posts
    142
    is there an LPAD or RPAD function in ActionScript?

  2. #2
    Aquarium drinker
    Join Date
    Nov 2000
    Location
    Greater than 45 degrees in Minkowski space
    Posts
    571
    No, but you could throw one together pretty easily. Here, try this:

    Code:
    String.prototype.lpad = function(len, pad)
    {
    	if( len > this.length )
    	{
    		var buf = '';
    		for( i = 0; i < len - this.length; i++)
    		{
    			buf += pad;
    		}
    		
    		nes = buf + this;
    	}
    	else
    	{
    		nes = this;
    	}
    	return nes;
    }
    Use it like this:

    myVar = 'Something';
    myVar = myVar.lpad(15, '*');

    myVar should be ******Something now. Hope this helps.

  3. #3
    Senior Member
    Join Date
    Mar 2002
    Posts
    142

    Thanks,

    Thanks a great deal,
    By the way when I performed an LPAD with 'spaces', the spaces just does NOT seem to align with the rest of my pattern in the field that I LPADed.
    For example:
    LPAD ("A", 5, "X") ---> would look like: "XXXXA", wherever
    LPAD ("A", 5, " ") ---> would look like: " A".

    How do I fix this?

    Help.

    Thanks,
    Raymond


  4. #4
    Aquarium drinker
    Join Date
    Nov 2000
    Location
    Greater than 45 degrees in Minkowski space
    Posts
    571
    Well, you have to use a monospace font, not sans or serif. Try Courier New in your field.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center