Click to See Complete Forum and Search --> : remove spaces
prokhaled
May 20th, 2002, 10:20 AM
Using JavaScript:
How can I remove spaces from string.
How can I remove right spaces and left spaces from this string " Hi "
punkpie_uk
May 20th, 2002, 10:42 AM
http://javascript.internet.com/forms/remove_xs_whitespace.html
prokhaled
May 20th, 2002, 11:02 AM
There is not any function in JavaScript to remove spaces such as (Trim function) In VBScript.
because some browser does not support VBScript so I want to use JavaScript
punkpie_uk
May 20th, 2002, 11:19 AM
no, trim doesnt exist but you can use this function to emulate it. Put it in the head of the document and call it like this...
newtxt = trim('fk dns fnds gkejgij');
... and spaces should be removed
function trim(txt){
var tmp = "";
var item_length = txt.length;
var item_length_minus_1 = txt.length - 1;
for (index = 0; index < item_length; index++){
if (txt.charAt(index) != ' '){
tmp += txt.charAt(index);
}else{
if (tmp.length > 0){
if (txt.charAt(index+1) != ' ' && index != item_length_minus_1){
tmp += txt.charAt(index);
}
}
}
}
return tmp;
}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.