Can anyone suggest a way to remove extra whitespaces from a string that exists in a Flash variable?
-
Can anyone suggest a way to remove extra whitespaces from a string that exists in a Flash variable? [more inside] I'm messing around with a Flash animation that started out as a http://www.jamesburnsdesign.com/tests/gibberish.html%20 It generates a nonsensical phrase from sentence fragments, but the result may have multiple whitespaces in it, and I need to remove them (unlike the JavaScript version, which automatically discards multiple whitespaces...). I think maybe the condenseWhite method may do this, but I can't figure out a simple way to implement it. Has anyone done this before?
-
Answer:
This will do it for ya: String.split(" ").join(""); Replacing String with whatever your variable is called.
jpburns at Ask.Metafilter.Com Visit the source
Other answers
Won't String.split(" ").join(""); remove ALL spaces from a string? If you just want multiple spaces converted to single spaces try this: s = "     This is a test    of the program.   "; // String.prototype.removeExtraSpaces = function() { tmp = this; while (tmp.indexOf("   ") != -1) { found = tmp.indexOf("   "); tmp = tmp.substr(0, found)+tmp.substr(found+1); } // deal with a possible stray at the start of the string if (tmp.substr(0, 1) == " ") { tmp = tmp.substr(1); } // deal with a possible stray at the end of the string if (tmp.substr(tmp.length-1, tmp.length) == " ") { tmp = tmp.substr(0, tmp.length-1); } return tmp; }; trace("["+s.removeExtraSpaces()+"]");
gwint
// only tested as javascript - don't have flash on this machine - methods exist in both while (aString.indexOf("Â Â ") != -1) { Â Â Â Â var anArray = aString.split("Â Â ") Â Â Â Â aString = anArray.join("Â ") }
TimeFactor
move (replaces(" ",sTmpString," ")) to sTmpString oh... Wait... You said Flash, not the http://www.visualdataflex.com/, that I've managed to destroy my C.V. with.
seanyboy
Thanks, all. This seems to work with my variable called "outPut"(adapted from TimeFactor's version): function fixIt(){ anArray =outPut.split(" "); return(anArray.join(" ")); } (this is previewing OK, I may need to fix after actually posting...)
jpburns
TimeFactor: Your method works great, unless there is space at the beginning of the string.
gwint
jpburns: If you know you'll never have more than two spaces in a row your version is preferable. Otherwise, you'll need the while loop. gwint: yup. or at the end.
TimeFactor
Yep... but for some reason the "while" method made Flash Player beachball, and then inform me that something in my code was taking a lot of time... ... since I'm making the pieces that get connected together, it's pretty easy to be assured that I won't have more than two spaces together. Thanks, again. It really helps to see an example like that.
jpburns
I've never used it, but http://www.jurjans.lv/flash/RegExp.html wrote a reg exp. class for flash. It might be worth looking into.
alan
Related Q & A:
- Going to Chennai India for 6 months can anyone suggest a safe clean possibly American or westernized area?Best solution by Yahoo! Answers
- How to remove extra fat from a body?Best solution by Arqade
- Can anyone suggest a good overhead projector that is not too expensive?Best solution by simforums.com
- Can anyone suggest me a unique brand name for my products?Best solution by eatmywords.com
- Can anyone suggest a good job site with jobs world wide?Best solution by anyworkanywhere.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.