Forum Discussion

Adagio's avatar
Adagio
Frequent Contributor
7 years ago

How to extract a string from between 2 other repeating strings

Hi,

 

This problem has been bothering me for sometime now. Could someone please help?

 

As shown in the snapshot below, I have to extract 0028441622 from this text on the picture. I'm able to read the whole text using the name mapping, but unable to write a logic which would extract the string  from between iLPN: and iLPN

 

Any help would be appreciated!

 

 

 

 

 

 

Thank you

Abhi  

  • Such tasks can usually be easy solved with the help of replace/split/join methods.

    Here is your specific task solved in JScript:

    var s = 'SOME TEXT\nItem Description:\nSOME OTHER TEXT\nINT:SOME TEXT AGAIN\niLPN:\n0028441622\niLPN:SOME TEXT AT THE END';
      
    var iLPN = s.replace('\n', '').split('iLPN:')[1];
    Log.Message(iLPN);
  • karkadil's avatar
    karkadil
    Valued Contributor

    Such tasks can usually be easy solved with the help of replace/split/join methods.

    Here is your specific task solved in JScript:

    var s = 'SOME TEXT\nItem Description:\nSOME OTHER TEXT\nINT:SOME TEXT AGAIN\niLPN:\n0028441622\niLPN:SOME TEXT AT THE END';
      
    var iLPN = s.replace('\n', '').split('iLPN:')[1];
    Log.Message(iLPN);
    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      karkadil wrote:

      Such tasks can usually be easy solved with the help of replace/split/join methods.

      Here is your specific task solved in JScript:

      var s = 'SOME TEXT\nItem Description:\nSOME OTHER TEXT\nINT:SOME TEXT AGAIN\niLPN:\n0028441622\niLPN:SOME TEXT AT THE END';
        
      var iLPN = s.replace('\n', '').split('iLPN:')[1];
      Log.Message(iLPN);

      If you"re not using JScript or JavaScript, you can use aqString still.  Set the List separator to iLPN: as karkadil with the split and reference the same item with aqString.GetListItem

    • Adagio's avatar
      Adagio
      Frequent Contributor

      karkadil  Thanks much. You've got it even better. Works pretty well. I'm going to use this one.

       

      Thank you

      Abhi

      • shankar_r's avatar
        shankar_r
        Community Hero

        One more option for you,

         

         

         

        function test(){
        Log.Message(getString("iLPN:","iLPN:");
        }
        function getString(staticStringStart,staticStringEnd){ var startPos = aqString.Find(messageString, staticStringStart, 0, false) + aqString.GetLength(staticStringStart); var endPos = aqString.Find(messageString, staticStringEnd, startPos + 1, false); return aqString.SubString(messageString, startPos, endPos - startPos); }

         

         

  • Look for ":" first, your string occurs right after the third ":"

    Then take the next 10 characters and that is your string

    If it isn't always 10 characters, then take all characters till you find "I" and that will tell you where to stop

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Question:

       

      When you examine that form, do each of the text labels identify as their own?  '

       

      That said, what Marsha_R suggests is the best way that I now how.  Use the aqString object and the "Find" method to find the string starting at a location and having a particular length.

      • Adagio's avatar
        Adagio
        Frequent Contributor

        Hello Robert,

         

        The content on that page might change(i.e. size of the string) as well as the string that I'm trying to extract. I can read the whole content as it's one panel.

        The easier option I thought would be to fetch a string that's present between LPN and iLPN. is there any way do do this even by using regex ?

         

        Thank you

        abhi