Link to home
Start Free TrialLog in
Avatar of isilver
isilver

asked on

Trim the spaces off a string

How do I remove the spaces from the left and right side of a string using Flash MX?
Avatar of stef4s
stef4s

str = " Fluffy "


if(str.charAt(0)==" "){
  str = str.substr(1);
}

if(str.charAt(str.length-1)== " "){
  str = str.substr(0,str.length-1)
}

trace(str)
also if there is more than one space replace the "if" with "while"
ASKER CERTIFIED SOLUTION
Avatar of rootdir
rootdir

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hate to pick on you rootDir, but why post such a coplex and overbarring code for a simple task?

isilver, if you did not know how to do this before, I would suggest you stick with the simple and efficient code written by stef4s
isilver,

 U wanted to remove spaces not single space from left and right side of string. It is just another method.

chill0123,

Give proper answers otherwise do not post unwanted comments.
Again you are wrong rudeDir...  if you read the question that was asked you will see that isilver wanted to "remove the spaces from the left and right side of a string"

I believe that my replies and many others that are posted through out these boards are valid comments that give support to a particular answer that was previously posted...  And as I recall you were the one that chastised me for closing a question with and answer...

You need to pick your battles a little wiser, and don't be hasty to post short and unwarranted answers when you have not read the questions... :)
isilver,

 U wanted to remove spaces not single space from left and right side of string. It is just another method.

chill0123,

Grow up child. Give proper answer otherwise do not post unwanted comments.If you donot understand problems then K U M S
<edited for flaming, rudness, and foul language.>
Again you are wrong rudeDir...  if you read the question that was asked you will see that isilver wanted to "remove the spaces from the left and right side of a string"

I believe that my replies and many others that are posted through out these boards are valid comments that give support to a particular answer that was previously posted...  And as I recall you were the one that chastised me for closing a question with and answer...

You need to pick your battles a little wiser, and don't be hasty to post short and unwarranted answers when you have not read the questions... :)
chill0123 I have reported this to comunity support. You are only flaming rootdir and did not offer your own suggestion or solution. Locking this question is rude. rootdir is entiteled to add his own solution although my solution works and was there first.
isilver please reject chill0123 proposed answer
This question was posted 4/27/02, and so far zero response from the Asker.  This is an IT Collaboration site and as such, ideas and recommendations, posted as comments are ideal.  The asker can always choose the first best comment, serving the need to convert to the Accepted Answer to then grade and close.  Please do not move questions to the Locked Question Queue by proposing an answer unless you are 100% certain your input is the first and only correct response, which I'm sure you'll agree is not the case here.  

chill0123 ->  Your comments here are not constructive and are definitely against the Guidelines, please read the information below.  If you have questions in this regard, post a zero point question in the Community Support topic area to get additional insights.  This link has been sent to Administration and the Proposed Answer rejected.

https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
https://www.experts-exchange.com/jsp/infoMemberAgreement.jsp

Moondancer - EE Moderator
thanks Moondancer
Moondancer, stef4s, and who ever else out there who is interested in the subject of closure:

It is clear to me that the purpose of this site is to solve IT related problems and give advice about solutions to those problems.  I have visited this Experts board on a daily basis for a while now, and have just recently decided to offer up my opinions and expertise as an experienced web/Flash designer.  This board provides great information, and I will continue to be a regular user, but there are plenty of things that should be changed about the format of this site.

Why give the user an option to "answer" a question if they will be chastised by the community?  And why let a question that has been asked and answered stay active for months or even years?  There is still an unresolved question about "Flash drop down menu" that was posted on 07/10/2000. What are the chances that DennisMcDougall ever comes back to this site to find out the answer?

EE say that you should post Comments if it is early in the Collaboration process, but when an issue has been solved and has been collecting dust from misc. comments, the question should be closed. And if it is a "bad thing" to submit an answer, then the moderators need to get to work and close out the question!

I think that this site if full of three kinds of users; individuals that need QUICK help with an IT problem, experts that enjoy solving these problems and offering up advice because they like the challenge, and misguided individuals who offer up quick and unexplained solutions hoping to get points. The majority of these questions go on endlessly and with out closure, because no one will "Answer" the proposed question, and the moderator will not close a question or award points until that has been done. This format needs to be changed so that questions can come to a conclusion.

If this site was set up to be a discussion board, then take away the points system to send away those looking for self worth through attaining maximum points.  If this is a site to see who is the smartest and most experienced person with way to much time on their hands then skip the "Netiquette" bull crap and let the "competition" begin. But if you want a site that offers expert solutions to IT problems then let the community "Answer" the f*@king questions so issues don't stay posted for YEARS!

by the way, this question has TWO "answers" and it is still not closed!
chill0123 please note that you selected Answer on something that you did not even have a suggestion to! If you have a problem with how something is done on this network take it up at community support. Don't take it up with us.
The reason I never use the Answer option is that if someone has a better solution they can post it.
Moondancer,stef4s

 I know why chill0123 id doing this. He wanted see accepted answers even he is not posting any comments/answers without losing points.
isilver it is time to review the posts and come to a conclusion.
rootdir,  what did you just type?

"I know why chill0123 id doing this. He wanted see accepted answers even he is not posting any comments/answers
without losing poin"

please learn correct english grammar before you try to explain yourself.

I selected answer, because the questions was resolved, and no one closed it.  I know that the only way a moderator will view/evaluate a question is if you select answer. Then after a really LONG period the process is ended with the points being awarded to the person with the best answer... I had no intention of getting any points, I just wanted isilver(or a moderator) to end this idiotic string of comments, buy receiving a "proposed answer" notification.

I have posted a "question" on the support board, but just like the rest of these questions, no one will ever give an  "Answer"

stef, if you are confident in your solution, then click on the answer button.

rudeDir, learn the lauguage

Moondancer, award the points to someone, so it does not stay posted until the year 2005!


c
I have meetings to attend today and am completely out of time, this has been referred to Administration.  Please refrain from further comments here not related to the help the Asker has requested; move it to Community Support instead.
Moondancer - EE Moderator
stef4s should get the points, because he answered the question first, and with a more efficient script that does exactly what isilver had asked.

Ian,

You seems to be some what of an authority figure(at least your title says that). Why has this site been set up with two choices when dealing with questions, when the community frowns on "answering" questions?  If you look at the lists of unanswered questions, you will find very outdated information that is over a year old and two Flash versions back?  There should be a time limit for unresolved questions, and have them archived or setup in an area that is specifically made for unanswered/hard questions...
Any thougts on that issue?  

chill
Hi chill,

As for the points reccomendation, thanks, I'll wait a wee while and if no one objects, I'll do that. Bear in mind I can split.

As for your points regarding points, let me address them.

You are right about the amount of "locked" questions awating grading, and the amount of questions with no answers provided. It is a problem.

We used to have 2 systems called Autograde, and Autodelete. What would happen is, if a question was "answered" and not graded/evaluated by a member after 30 days (eg) , the system would remind the member, and then award to the proposed answer, and give a grade based on the experts last 10 grades. So if the expert has all A's, the expert gets a A.
For Autodelete, it was much the same thing, except the question would be deleted and the points not returned.

This, for a long time helped this problem.

However, the site went through a huge change (I'm not sure if you are aware of the history of EE, but I wont elaborate here) and since then, the priority has been one issue, site stability. Once this key area has been addressed then all the other things (like this) can be addressed. Theres no point in having a Autograde if the site has been down, its not fair. So thats were we all. If you click the Community News link (from "Whats new") then you can see all the mechanisms we are setting up for consultation with users of the site to address this.

Sound ok?

Ian
your site not mine...  

I still think this site needs an area of unanswered questions that can be graded by moderators, because people like me enjoy trying to figure out issues that others cannot resolve... kinda like riddles or puzzles...

thanks for trying to resolve this issue...

c

isilver,

I don't care what other says here if you check date and time. I will explain how my comment is more right.

Check stef4s first comment 04/28/2002 11:45PM PST

It is not solving your problem.
If you take str = "   Fluffy    ", with his solution it will only delete first and last blank charater.
So you will get "  Fluffy   " result which is wrong

Check out his next comment at 04/29/2002 12:01AM PST

Still now he is suggesting to use 'if' and 'while' loop.
But my point this comment came after my comment

Check my comment date 04/29/2002 11:20AM PST

Prove me that my comment is wrong. Some jurk is saying it is complex, but it is checking all possibilities.

RootDir
chill0123

>your site not mine...  

True, but the site is nothing without the people that us it, so we need to listen.

>I still think this site needs an area of unanswered questions that can be graded by moderators

The mods are goin through TA's cleaning up, but there are only so many of them.

>thanks for trying to resolve this issue...

Thanks....

rootdir,

no probs, I can split to both.

Ian



again with the rudeness, poor grammar/spelling, and inability to read the original question...

It really does not matter who gets the points here rudeDir...  you just can't get it through your head that stef4s has answered EVER part of isilver's question, and s/he did it before you! Why did you type: "another way to remove space" at the beginning of you comment, if you were the first person to have their comment posted?  

Let me break down the question and answer for you rudeDir, because you can't seem to read the comments that are posted above...

The Question:  "How do I remove the spaces from the left and right side of a string using Flash MX?"

- this question is asking for a solution that takes any amount of blank spaces(1, 2, 3, 500) and removes them...

stef4s used the following simple code to solve that problem:
-------------------
str = " Fluffy "


if(str.charAt(0)==" "){
 str = str.substr(1);
}

if(str.charAt(str.length-1)== " "){
 str = str.substr(0,str.length-1)
}

trace(str)
-------------------

he posted a comment right after that, which explains how to "remove the spaces from the left and right side of a string" if there were more than one blank space before or after the string.  

The original question ONLY asked to remove the spaces to the left and right side of a string. There is no need to check for all possibilities, because isilver did not ask for that...  your code could have checked for lice on people's head, but that is not needed...  Your code is like using Dreamweaver to write a simple roll over script... or Microsoft Word to write your HTML for you... it is over complicated and most of the code is not needed.

A simple question that needed a simple answer.  stef4s provided a better solution, and it was posted to the board first. If you were first, then why is your comment placed below BOTH of stef4s comments?

rudeDir, you are exactly the type of person that I mentioned earlier who is only in this for the points.

Luckily isilver never returned to be pursuaded by your poorly worded and grammatically incorrect comments. And if you are going to insult someone, then please learn how to spell the word(jurk) first!

c



" Fluffy "
copy and pasted from the top. (my comment)

"   Fluffy    " pasted from your comment(rootdir).

also I did mention that replacing the "if" with "while" will remove more spaces. therefore the combinations of comments answer the question.

rootdir please refrain from typing bull! I have never been so blind to see that your solution has strong points. (your code is encapsulated inside functions which is good.) On the other hand MY ANSWER IS CORRECT AND WILL WORK!

I NEVER critisized your solution so I would appreciate it if you did not critize mine!
" Fluffy "
copy and pasted from the top. (my comment)

"   Fluffy    " pasted from your comment(rootdir).

also I did mention that replacing the "if" with "while" will remove more spaces. therefore the combinations of comments answer the question.

rootdir please refrain from typing bull! I have never been so blind to see that your solution has strong points. (your code is encapsulated inside functions which is good.) On the other hand MY ANSWER IS CORRECT AND WILL WORK!

I NEVER critisized your solution so I would appreciate it if you did not critize mine!
stef4s,

   Check my above comment I never said that your code is wrong. Check I also said that you have pointed that he/she has to use "if" with "while" to remove more spaces.

   You and I know that, if there are more spaces than your first comment will not work properly.

   I never crticized your solution. Because of some "JURK" I posted my above comment. If you get heart from my above comment then I am sorry.

RootDir
isilver time to comment
isilver,

  Are u checking our comments? Do not keep your question hanging?

RootDir
it is very clear that isilver has gone elsewhere to have his question answered, so please reframe from posting more "please comment/award points" comments to this board...

The Community Director should has awarded the points by now, please contact him directly so I do not receive any more disrupting email about this subject...

thank you

c
chill0123,  If you do not want to receive anymore comments from this thread or emails, hit the Unsubscribe button down below.  If you do that then other people here will probably appreciate it as well.  This is a community.  And a team effort.  Sometimes you get points sometimes you dont and sometimes they get split.  But Any comment is better than a wrong answer or an answer that is not quite right.  So untill we hear from Isilver or unless the moderators deem it necessary to close the question.  Then that it where we are at.  I understand your frustrations with the opened questions.  There are many of them out there....there are also many locked ones out there too which suck just as much because people use the answer butting thinking they are 100% correct and missed the picture or missed part of the question or the whole question to begin with as you suggested above... (no offense to anyone) just stating what was said.  Anyway do like your name says and Chill...Life is good. questions will get answered some will close some will lock and some will forever be opened...But for now we will all try our best to do what we can to close questions with the best possible answers from everyone.  
Avatar of isilver

ASKER

It took me a while to get back to this question but I am here.  A lot has happened I see.  
isilver,

Could you explain a little on why you chose rootdir's comments and how it helped you?  It would benefit the discussion.  And may bring some enlightenment upon the situation that many of us do not understand?  Thanks!

I think the answer button should be removed. There are very few instances where it is actually usefull. Questions should be marked for a "points vote" or something after 1 month.
Hey chill0123, see ya!  You are out of here.
well that could have gone better.
Please don't post any more comments. There is no option "turn off email notification" for such accepted comment questions.

Comtech,

  Please bring this to the attention of Community Support.