[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1656
  • Last Modified:

Removing Line Breaks from a String

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
Fatlog
Asked:
Fatlog
  • 3
1 Solution
 
krishnaprathabCommented:
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
 
FatlogAuthor Commented:
this doesnt really work

i need to be able to do something like the way you can use split/join to replace characters
0
 
krishnaprathabCommented:
Hi,

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

Thanks,
KP
0
 
krishnaprathabCommented:
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now