Not a Member Yet,
Click here to Register

ID: 229
Viewed: 3707
Added: May 20, 2002
Version:
Snippet uploaded by: snippet
Written By: punkpie_uk
Demo: Sorry, no demo



User Rated at: 4 Stars4 Stars4 Stars4 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

I thought this would come in handy for someone wanting to trim whitespace from a string or a word.

it will trim all the whitespaces from a work like so: " hi "

it will make it so it looks like this "hi"

Browsers: all

<!---Head--->
<script language="javascript" type=text/javascript">
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;
}
</script>

<!---Body--->


 // then call it like this


newtxt = trim('fk dns fnds gkejgij');



No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2024 snippetlibrary.com All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!