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

x
?
Solved

Flash Trim Function

Posted on 2004-11-30
3
Medium Priority
?
651 Views
Last Modified: 2010-08-05
I am trying to trim a string with extra white space and line breaks.  I a have tried using the following AS from:

http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_20294500.html?query=%22flash+trim%22&clearTAFilter=true

Example:

function LTrim(str) {
      var whitespace = new String(" \t\n\r");
      var s = new String(str);
      if (whitespace.indexOf(s.charAt(0)) != -1) {
            var j = 0, i = s.length;
            while (j<i && whitespace.indexOf(s.charAt(j)) != -1) {
                  j++;
            }
            s = s.substring(j, i);
      }
      return s;
}
function RTrim(str) {
      var whitespace = new String(" \t\n\r");
      var s = new String(str);
      if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
            var i = s.length-1;
            while (i>=0 && whitespace.indexOf(s.charAt(i)) != -1) {
                  i--;
            }
            s = s.substring(0, i+1);
      }
      return s;
}
function Trim(str) {
      return LTrim(RTrim(str));
}


myString = "hello world   ";
trace(myString);
Trim(myString);
trace(str);

The str trace comes back as undefined.  Is there something wrong with the syntax?  Any other suggestions for a trim function?

TIA,

Terry
0
Comment
Question by:splendorx
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
AgentSmith007 earned 500 total points
ID: 12707429
myString = "hello world   ";
trace(myString);
Trim(myString);
trace(str);

CHANGE TO:

myString = "hello world   ";
trace(myString);
str = Trim(myString);
trace(str);
0
 
LVL 1

Author Comment

by:splendorx
ID: 12707466
Thanks for the help!!
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12707604
Glad to help!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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 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 goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses
Course of the Month19 days, 16 hours left to enroll

873 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