Heres a more object oriented way to define the trim function (copied
straight from the JScript documentation available for download from MSDN).
Its works for JScript 5 and JavaScript 1.3

// Add a function called trim as a method of the prototype
// object of the String constructor.
String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

// A string with spaces in it
var s = "    leading and trailing spaces    ";

// Displays "    leading and trailing spaces     (35)"
window.alert(s + " (" + s.length + ")");

// Remove the leading and trailing spaces
s = s.trim();
// Displays "leading and trailing spaces (27)"
window.alert(s + " (" + s.length + ")");
----- Original Message -----
From: "Hoorn, Michiel van" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, April 27, 2001 3:07 PM
Subject: Re: Off Topic: Trim


> Sorry, made an error, o must be 0 :-)
> So this will work :-)
>
> > function trim(incomingString){
> >   while(''+incomingString.charAt(incomingString.length-1)==' '){
> >     incomingString =
incomingString.subString(0,incomingString.length-1);
> >   }
> >   return incomingString;
> > }
> >
> > ----------
> > From:         Hoorn, Michiel van
> > Sent:         Friday, April 27, 2001 11:34 AM
> > To:   [EMAIL PROTECTED]
> > Subject:      RE: Off Topic: Trim
> >
> > Nope, but this works, written by me :-)
> >
> > function trim(incomingString){
> >   while(''+incomingString.charAt(incomingString.length-1)==' '){
> >     incomingString =
incomingString.subString(o,incomingString.length-1);
> >   }
> >   return incomingString;
> > }
> >
> >
> >
> >       ----------
> >       From:   Eduardo Miguel Oliveira[SMTP:[EMAIL PROTECTED]]
> >       Reply To:       [EMAIL PROTECTED]
> >       Sent:   Friday, April 27, 2001 11:24 AM
> >       To:     [EMAIL PROTECTED]
> >       Subject:        Off Topic: Trim
> >
> >       Is there anything similar to VBScript's TRIM in JAVASCRIPT???
> >
> >       Tx
> >
> >
> >       Eduardo Oliveira
> >
> >       S-Tecno - Servi�os em Tecnologias
> >                         de Informa��o
> >
> >       R. General Ferreira Martins, 10, r/c B
> >       Miraflores                1495 - 137 Alg�s
> >
> >       Tel 21 412 15 80     Fax 21 412 15 83
> >
> >
> >
==========================================================================
> > =
> >       To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > JSP-INTEREST".
> >       For digest: mailto [EMAIL PROTECTED] with body: "set
> > JSP-INTEREST DIGEST".
> >       Some relevant FAQs on JSP/Servlets can be found at:
> >
> >        http://java.sun.com/products/jsp/faq.html
> >        http://www.esperanto.org.nz/jsp/jspfaq.html
> >        http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> >        http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> >
> >
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to