Solved

Removing Line Breaks from a String

Posted on 2004-03-31
4
1,646 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
ID: 10724977
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
ID: 10730669
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
ID: 10730828
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
ID: 10773412
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
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): …
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

792 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