I'd probably still put it in some sort of util function you can call
anywhere.


function eliminateSpaces(phrase:String):String
{
        return phrase.split(' ').join('');
}

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Rákos Attila
Sent: Tuesday, July 24, 2007 4:35 PM
To: Mendelsohn, Michael
Subject: Re: [Flashcoders] Returning a String fails


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:      flashcoders@chattyfig.figleaf.com
<flashcoders@chattyfig.figleaf.com>
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

*/
_______________________________________________
Flashcoders@chattyfig.figleaf.com
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-=

_______________________________________________
Flashcoders@chattyfig.figleaf.com
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

_______________________________________________
Flashcoders@chattyfig.figleaf.com
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