8 Replies Latest reply on Feb 11, 2016 9:24 AM by senechia

    Extract text from a string of text

    senechia Level 1

      I have this text in a text field:  "555-555-5555 PAUL ADRIANO 11596 MAIN ST  1/3/2013" is there a way for me to extract just the phone number and put it into another text field of its own?

        • 1. Re: Extract text from a string of text
          George_Johnson MVP & Adobe Community Professional

          Will it always be the first 12 characters of the string, or could it every be incomplete (e.g., 555-5555) or some other format like (555) 555-5555?

          • 2. Re: Extract text from a string of text
            senechia Level 1

            It will always be the first 12 characters. I would also like to pull the name, address, and date out of the string if possible. The only constant lengths of the string is the phone number, the date could be 1/3/2013 or it could be 12/13/2013, in other words, 8 or 10 charachters long. The name and address length is obviously unknown.

            • 3. Re: Extract text from a string of text
              senechia Level 1

              Here is an example of another string

               

              702-555-5555 GASTELUM NOEL & GALLEGO-EGURROLA MARIBEL  1328 N SLOAN LN  1/4/2013

              • 4. Re: Extract text from a string of text
                try67 MVP & Adobe Community Professional

                You should read about Regular Expressions and the various methods of the String object.

                Basically, if something has a fixed length (at a known position) or a known pattern it's pretty easy to extract.

                 

                For example, you can extract the phone number like this:

                var myString = "702-555-5555 GASTELUM NOEL & GALLEGO-EGURROLA MARIBEL  1328 N SLOAN LN  1/4/2013";
                var phoneNumber = myString.substring(0, 12);
                

                 

                And the date can be extracted using a RegExp pattern, like this:

                var dateString = /\d{1,2}\/\d{1,2}\/\d{4}$/.exec(myString)[0];
                

                 

                Anything else you'll have to figure out the logic behind, or maybe achieve by removing the bits that you can identify from the main string.

                • 5. Re: Extract text from a string of text
                  senechia Level 1

                  What if the string has a comma delimiter between the phone,name,address,and date like this: 702-555-5555,GASTELUM NOEL & GALLEGO-EGURROLA MARIBEL,1328 N SLOAN LN,1/4/2013

                   

                  Could it be done then?

                  • 6. Re: Extract text from a string of text
                    try67 MVP & Adobe Community Professional

                    Sure. In that case you can split the string with the comma as a delimiter and then process the items in the resulting array.

                    It will look something like this:

                     

                    var myString = "702-555-5555,GASTELUM NOEL & GALLEGO-EGURROLA MARIBEL,1328 N SLOAN LN,1/4/2013";
                    var items = myString.split(",");
                    if (items.length==4) {
                        var phoneNumber = items[0];
                        var name = items[1];
                        var address = items[2];
                        var date = items[3]
                    }
                    
                    • 7. Re: Extract text from a string of text
                      senechia Level 1

                      Ok...what am I doing wrong? I put this on a button with a mouse up trigger

                       

                      var myString = this.getField("Text1").value;

                      var items = myString.split(",");

                      if (items.length==4) {

                          var phoneNumber = items[0];

                          var name = items[1];

                          var address = items[2];

                          var date = items[3];

                          var one = this.getField("Text2").value;

                          var two = this.getField("Text3").value;

                          var three = this.getField("Text4").value;

                          var four = this.getField("Text5").value;

                       

                          {one.value=phoneNumber.value};

                          {two.value=name.value};

                          {three.value=address.value};

                          {four.value=date.value};

                      }

                      • 8. Re: Extract text from a string of text
                        senechia Level 1

                        Ok... Got this to work

                         

                        var myString = this.getField("Text1").value;

                        var items = myString.split(",");

                        if (items.length==4) {

                            var phoneNumber = items[0];

                            var name = items[1];

                            var address = items[2];

                            var date = items[3];

                            var one = this.getField("Text2");

                            var two = this.getField("Text3");

                            var three = this.getField("Text4");

                            var four = this.getField("Text5");

                         

                            {one.value=phoneNumber};

                            {two.value=name};

                            {three.value=address};

                            {four.value=date};

                        }