Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Removing all spaces from user input

EmilsEmils Posts: 2Member
I need to come up with a script that can edit user input, and remove all spaces contained therein.

Any ideas?

Comments

  • Josh CodeJosh Code Posts: 675Member
    [b][red]This message was edited by Josh Code at 2002-10-8 19:43:29[/red][/b][hr]
    : I need to come up with a script that can edit user input, and remove all spaces contained therein.
    :
    : Any ideas?
    :

    Make a function to remove spaces from a given string parameter.

    declare a variable to store the index of the space character in the string.

    set this variable to the location of the space using the string's method "indexOf".

    While this index is greater than 0, keep removing the space characters.

    Here is the code:

    [code]
    function clearspaces(s)
    {
    var i1; // stores the index
    i1=s.indexOf(" ",1);
    while (i1>0)
    {
    s = s.slice(0,i1)+s.slice(i1+1,999); // remove the space
    i1=s.indexOf(" ",1);
    }
    return s;
    }
    [/code]


Sign In or Register to comment.