Thanks Joules left a comment to let me konw that the language attribute for the script tag is deprecated (the article trim a string from white space by JavaScript function ).I wrote another javascript function for trim a string from white space at the front.(It will need some change for RTrim and Trim),I don’t konw there is faster way than below,if you know tell me pls.
- function LTrim(str) {
- var i;
- var len = str.length;
- for( i=0; i<len; i++ )
- {
- if( str.charCodeAt(i) == 160 )
- {
- str = str.substring(1, str.length );
- i--;
- len--;
- }
- else
- {
- break;
- }
- }
- return str;
- }
comment:160 is the char code for white space.

January 23rd, 2008
Ntt.cc 








Posted in
Tags: 
RSS Feed
Email Feed
Try this…
function trim(value) {
return value.replace(/^\s+|\s+$/g, ”);
}
hey,Nate
Thanks for your function.I tried it at IE6.0 and FireFox2.0
The result is:
FF2 is OK but can not be used with IE6…
There was no error but the white space can not be trimmed
[...] This extension splits the string by given separator and returns an array with trimmed items. It uses the trim() extension at trim a string from white space by JavaScript function or Another JavaScript function for trim a string from white space. [...]
/**
* Returns a copy of string without leading and trailing whitespace.
* Whitespace is defined as {char c | c <= ‘ ‘}.
*
* Note: We avoid regular expressions in implementation to support older user agents.
*/
function trim(string) {
/* Lookup the LENGTH of string. */
var LENGTH = string.length;
/* Find the first character that is not whitespace. */
var beginIndex = 0;
while (beginIndex != LENGTH && string.charAt(beginIndex) <= ‘ ‘) {
beginIndex++;
}
/* If all characters are whitespace then return the empty String. */
if (beginIndex == LENGTH) {return “”;}
/* Find the last character that is not whitespace. */
var endIndex = LENGTH;
while (endIndex != beginIndex && string.charAt(endIndex – 1) <= ‘ ‘) {
endIndex–;
}
/*
* If no leading or trailing whitespace found then return the string,
* otherwise return the substring without leading and trailing whitespace.
*/
return ((beginIndex == 0) && (endIndex == LENGTH)) ?
string : string.substring(beginIndex, endIndex);
}
Your blog software messed up the code. The second while loop uses the postfix decrement operator, and the quotes should be either the single ASCII quote or the double ASCII quote.
[...] a previous post trim a string from white space by JavaScript function ( or Another JavaScript function for trim a string from white space ) and JavaScript function-Splits the string by given separator and returns an array with trimmed [...]
Dear Sir
I want to Know how can i find Space in String in VB Script ASP