Using JavaScript:
How can I remove spaces from string.
How can I remove right spaces and left spaces from this string " Hi "
Printable View
Using JavaScript:
How can I remove spaces from string.
How can I remove right spaces and left spaces from this string " Hi "
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
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...
... and spaces should be removedCode:newtxt = trim('fk dns fnds gkejgij');
Code: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;
}