Solved

Removing Line Breaks from a String

Posted on 2004-03-31
4
1,640 Views
Last Modified: 2012-08-14
I have an input form built in flash.

There is an address field  on the form and it is multiline which allows the user to hit return/enter to move to the next line and continue their address.

WHen the user hits submit on the form i want to remove the line breaks before i send the data.

how do i remove the line breaks????????
0
Comment
Question by:Fatlog
  • 3
4 Comments
 
LVL 9

Expert Comment

by:krishnaprathab
Comment Utility
Hi,

  You can use escape(myText.text) which gives you teh URL encoded string.

Example :

Suppose I enter the below mentioned text in my input text box foor which the instance name is myText :

John
270, Wall Street,
Washington

and affix the action below on a button:

on (release) {
      trace(escape(myText.text));
}

the Ouput is :
John%0D270%2C%20Wall%20Street%2C%0DWashington

Since, this is already URL Encoded you can directly send the data to the URL or you can use a string manipulation fucntion to get rid of yur %0D and  %DC stuffs.

Hope this helps !

Thanks,
-KP
0
 

Author Comment

by:Fatlog
Comment Utility
this doesnt really work

i need to be able to do something like the way you can use split/join to replace characters
0
 
LVL 9

Expert Comment

by:krishnaprathab
Comment Utility
Hi,

 Please upload your file to some location and let me know. I will correct it and give you.

Thanks,
KP
0
 
LVL 9

Accepted Solution

by:
krishnaprathab earned 25 total points
Comment Utility
One more try:

1) Write the below listed function in your root timleine (I have not written this code I found it in Actionscript.org)

String.prototype.searchreplace=function(find,replace) {
        var string=this
        var counter
        while (counter<string.length) {
                var start = string.indexOf(find, counter);
                if (start == -1) {
                        break;
                } else {
                        var before=string.substr(0,start)
                        var after=string.substr(start+find.length,string.length)
                        string=before+replace+after;
                        var counter=before.length+replace.length
                       
                }
        }
        return string;
}

2) On your buttons onRelease event write the action :

on (release) {
      myStr = escape(myText.text);
      myStr = myStr.searchreplace("%20"," ");
      myStr = myStr.searchreplace("%0D",",");
      myStr = myStr.searchreplace("%2C",",");
      trace(myStr);
}

3) Restrict your input text field to only numbers and characters.

4) Now when you type :

John Greenhow
120 Wall Street
Washington DC

in the input text field and click on the button it will trace :

John Greenhow,120 Wall Street,Washington DC

There is no other way to achive what you want.

Hope this helps !

PN: Please close this question.

Thanks,
KP
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now