something like ...
function myBestTrim( str ){
var start = -1, end = str.length;
if(end < 1000)
return str.replace(/^\s+|\s+$/g, "");
while(str.charCodeAt( --end ) < 33);
while(str.charCodeAt( ++start ) < 33);
return str.slice( start, end + 1 );
};
On Tue, Nov 4, 2008 at 10:10 PM, Andrea Giammarchi <
[EMAIL PROTECTED]> wrote:
> But in this case you are checking twice for each character, start less than
> end plus the other check.
> For small strings the best option culd be return the regexp version
> /^\s+|\s+$/g while for strings with length more than N (dunno which length
> is big enough) we can use my last proposal without problems, a charcode
> instead of start < end wont make the difference, IMO :-)
>
>
> On Tue, Nov 4, 2008 at 10:02 PM, Ariel Flesler <[EMAIL PROTECTED]> wrote:
>
>>
>> That does, but will iterate doubly for strings made of spaces. That's
>> why I added the check.
>
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" 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/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---