FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM?

R

Randy Webb

Dr J R Stockton said the following on 2/25/2007 9:33 AM:
Others have already asked you to make better use of whitespace in FAQ
code.

They have? When and where? Besides, the only thing I changed -
whitespace wise - was the Trim line and that was more for Usenet posting
than anything. Either way, it is staying the way it is.
 
E

Evertjan.

Randy Webb wrote on 25 feb 2007 in comp.lang.javascript:
Dr J R Stockton said the following on 2/25/2007 9:33 AM:

They have? When and where? Besides, the only thing I changed -
whitespace wise - was the Trim line and that was more for Usenet posting
than anything. Either way, it is staying the way it is.

I did ask for more white space.

It makes demo code more easily readable, IMHO.

btw, I would prefer the use of ;s too:

String.prototype.LTrim =
function() {
return this.replace(/^\s+/, '');
};
 
E

Evertjan.

David Golightly wrote on 25 feb 2007 in comp.lang.javascript:
By the way, is there a naming convention for method names vs. object
names? Seems perhaps more consistent with builtin methods to use
camelCase instead of PascalCase for methods, thus String.lTrim,
String.rTrim, and String.trim (compare String.charAt,
String.toLowerCase, string.indexOf) should be preferred to
String.LTrim, String.RTrim, and String.Trim, no?

This was already discussed in this thread,
however without consensus result.

I agree with your point.
 
R

Randy Webb

Evertjan. said the following on 2/25/2007 4:27 PM:
Randy Webb wrote on 25 feb 2007 in comp.lang.javascript:


I did ask for more white space.

It makes demo code more easily readable, IMHO.

I don't agree with the "more easily readable" but you want whitespace,
you get it.
btw, I would prefer the use of ;s too:

Yeah, makes it more "readable"
String.prototype.LTrim =
function() {
return this.replace(/^\s+/, '');
};

Changed. The names are also changed:

String.prototype.lTrim=
function()
{
return this.replace(/^\s+/,'');
}
String.prototype.lTrim=
function()
{
return this.replace(/\s+$/,'');
}
String.prototype.trim=
function()
{
return this.replace(/^\s+|\s+$/g,'');
}
 
E

Evertjan.

Randy Webb wrote on 26 feb 2007 in comp.lang.javascript:
Evertjan. said the following on 2/25/2007 4:27 PM:
Randy Webb wrote on 25 feb 2007 in comp.lang.javascript: [...]

It makes demo code more easily readable, IMHO.

I don't agree with the "more easily readable"

I ment for a newbee, as the FAQ is most useful to.
Later on it seems handy to compact these library-like functions
as not to clutter the "real" programming.
but you want whitespace, you get it.

Thanks, got it. ;-)
Yeah, makes it more "readable"


Changed. The names are also changed:

String.prototype.lTrim=
function()
{
return this.replace(/^\s+/,'');
}
String.prototype.lTrim=
function()
{
return this.replace(/\s+$/,'');
}
String.prototype.trim=
function()
{
return this.replace(/^\s+|\s+$/g,'');
}

Could we have a space before the = too?

String.prototype.trim =
 
R

Randy Webb

Evertjan. said the following on 2/26/2007 2:14 AM:
Randy Webb wrote on 26 feb 2007 in comp.lang.javascript:
Evertjan. said the following on 2/25/2007 4:27 PM:
Randy Webb wrote on 25 feb 2007 in comp.lang.javascript: [...]
It makes demo code more easily readable, IMHO.
I don't agree with the "more easily readable"

I ment for a newbee, as the FAQ is most useful to.
Later on it seems handy to compact these library-like functions
as not to clutter the "real" programming.

Very true.

Could we have a space before the = too?

String.prototype.trim =

Done locally.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
String.prototype.lTrim=
function()
{
return this.replace(/^\s+/,'');
}
String.prototype.lTrim=
function()
{
return this.replace(/\s+$/,'');
}
String.prototype.trim=
function()
{
return this.replace(/^\s+|\s+$/g,'');
}


String.prototype.lTrim =
function()
{
return this.replace(/^\s+/, '');
}

etc.

Personally, I see no need for isolating the braces, though I know others
like it. To me it smacks of pay-by-the-yard coding, a practice
doubtless unknown in mainland Europe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top