3 Replies Latest reply on Oct 22, 2006 1:43 PM by thejokerman05

    plus (+) and minus (-)

    thejokerman05
      This works;
      var namn = field._name;
      field.text = (namn +"_txt");

      This doesn't;
      var namn = field._name;
      field.text = (namn -"_txt");

      How to leave out "_txt" from name? I could rename my instance but just want to know why this doesn't work.
        • 1. Re: plus (+) and minus (-)
          Level 7

          "thejokerman05" <webforumsuser@macromedia.com> wrote in message
          news:ehgg45$ahi$1@forums.macromedia.com...
          > This works;
          > var namn = field._name;
          > field.text = (namn +"_txt");
          >
          > This doesn't;
          > var namn = field._name;
          > field.text = (namn -"_txt");
          >
          > How to leave out "_txt" from name? I could rename my instance but just
          > want to
          > know why this doesn't work.
          >

          namn is a String. Strings can be concatenated with a + because it makes
          sense.
          But subtracting it could mean many things like removing matches from the end
          of the String, or removing all matches.

          Instead there are other ways to do this, for instance...

          field.text = field._name.split("_txt")[0];


          • 2. Re: plus (+) and minus (-)
            NSurveyor Level 2
            The way you are using + is not addition, but rather concatenation. The - is only for subtraction, there is no string "subtraction". However, you can take a substring or split your string on _txt and take the first element:

            var namn = field._name;
            field.text = namn.substr(0,-4);//take all but the last 4 characters

            var namn = field._name;
            field.text = namn.split('_txt')[ 0 ] // take everything before the first _txt encounter
            • 3. Re: plus (+) and minus (-)
              thejokerman05 Level 1
              Thanks a lot. Now I've learned something new. Great!