You should rethink what you are doing :) If the string passed contains
more than 1 space, your function will not return anything. Do you see
a return statement here?

if (phrase.indexOf(" ") != -1) {
  eliminateSpaces(phrase);
}

Well, and the whole function seems to be an overkill, you can reach
the same result with a single line:

phrase = phrase.split(" ").join("");

  Attila

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
From:    Mendelsohn, Michael <[EMAIL PROTECTED]>
To:      [email protected] <[email protected]>
Date:    Tuesday, July 24, 2007, 10:22:06 PM
Subject: [Flashcoders] Returning a String fails
--====----====----====----====----====----====----====----====----====----===--
Hi list...

I've written a simple routine to eliminate spaces from a user entered
string.  But, it won't return the string.  I'm sure it's something
silly.  Can anyone shed light?

- MM


function eliminateSpaces(phrase:String):String {
        var foundSpace = phrase.indexOf(" ");
        if (foundSpace != -1) {
                phrase = String(phrase.substring(0, foundSpace) +
phrase.substring(foundSpace + 1));
                if (phrase.indexOf(" ") != -1) {
                        eliminateSpaces(phrase);
                } else {
                        trace("output: " + phrase);
                        return phrase;
                }
        }
}
var s:String = eliminateSpaces("moe and larry and curly");
trace(s);

/* RESULT:

output: moeandlarryandcurly
Undefined

*/
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to