On 22/04/2008, braudes <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I notice that the String class doesn´t have some simple methods. So, I
> added these:
>
> ltrim: function() {
> var re = /\s*((\S+\s*)*)/;
> return this.replace(re, "$1");
> },
>
> rtrim: function() {
> var re = /((\s*\S+)*)\s*/;
> return this.replace(re, "$1");
> },
>
> trim: function() {
> return this.rtrim().ltrim();
> },
>
> invert: function() {
> var len = this.length;
> var str = "";
> for (var i = len - 1; i > -1 ;i--){
> str += this.charAt(i);
> }
> return str;
> }
I think we'll all got variations on this ...
addCommas : function(s_Decimal, s_Thousand, s_SplitDecimalUsing){
return addCommas(this, s_Decimal, s_Thousand, s_SplitDecimalUsing);
},
left : function(i_Len){
return this.substring(0, i_Len);
},
lTrim : function(s_Trim){
return this.replace(((0 == arguments.length) || '' == s_Trim) ?
"/^\\s+/" : "/^" + s_Trim + "+/", '');
},
mid : function(i_Start, i_End){
i_Start = (!i_Start) ? 0 : i_Start;
i_End = (!i_End || i_End > this.length) ? this.length : i_End;
i_End = (i_End != this.length) ? i_Start + i_End : i_End;
return this.substring(i_Start, i_End);
},
pad : function(i_padLen, s_padStr, i_padType){
return s_padStr || (s_padStr = " "), (i_padLen -= this.length) > 0 ?
(s_padStr = new Array(Math.ceil(i_padLen / s_padStr.length) +
1).join(s_padStr)).substr(0, i_padType = !i_padType ? i_padLen :
i_padType == 1 ? 0 : Math.ceil(i_padLen / 2)) + this +
s_padStr.substr(0, i_padLen - i_padType) : this;
},
right : function(i_Len){
return this.substring((this.length - i_Len), this.length);
},
rTrim : function(s_Trim){
return this.replace((0 == arguments.length) ? "/\\s+$/" : "/" +
s_Trim + "+$/", '');
},
trim : function(s_Trim){
if (0 == arguments.length){
return this.replace(/^\s+|\s+$/g, '');
} else {
return this.lTrim(s_Trim).rTrim(s_Trim);
}
}
--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---