Re: Is there any function as Trim in Jscript/JavaScript?
From: Randy Webb (hikksnotathome_at_aol.com)
Date: 06/24/04
- Next message: Saint Jude: "Re: Is there any function as Trim in Jscript/JavaScript?"
- Previous message: Christoph Basedau: "Re: Is there any function as Trim in Jscript/JavaScript?"
- In reply to: Vilmar Brazão de Oliveira: "Is there any function as Trim in Jscript/JavaScript?"
- Next in thread: Saint Jude: "Re: Is there any function as Trim in Jscript/JavaScript?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 24 Jun 2004 19:45:19 -0400
Vilmar Brazão de Oliveira wrote:
> Hi,
>
> Is there any function as Trim in Jscript/JavaScript?
> I look at Ms-JScript tutoria which comes with ms-visual studio 6.0, but did
> not find anything untill now.
> I try to check the length, but it returns me size when I put
> a string with some or a lot of white spaces.
> In VB or VBScript the funciont Len with a string with some or a lot of
> white spaces BRINGS ME 0()ZERO!
http://www.jibbering.com/faq/#FAQ4_16
Gives:
function LTrim(str) {
for (var k=0; k<str.length && str.charAt(k)<=" " ; k++) ;
return str.substring(k,str.length);
}
function RTrim(str) {
for (var j=str.length-1; j>=0 && str.charAt(j)<=" " ; j--) ;
return str.substring(0,j+1);
}
function Trim(str) {
return LTrim(RTrim(str));
}
And then you simply Trim(YourStringName)
-- Randy Chance Favors The Prepared Mind comp.lang.javascript FAQ - http://jibbering.com/faq/
- Next message: Saint Jude: "Re: Is there any function as Trim in Jscript/JavaScript?"
- Previous message: Christoph Basedau: "Re: Is there any function as Trim in Jscript/JavaScript?"
- In reply to: Vilmar Brazão de Oliveira: "Is there any function as Trim in Jscript/JavaScript?"
- Next in thread: Saint Jude: "Re: Is there any function as Trim in Jscript/JavaScript?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|