Part 5.3 - Text Actions: Parse Text and Get Subtext

Part 5.3 - Text Actions: Parse Text and Get Subtext

In this article, we are talking about the difference between Parse Text and Get Subtext, and how to use Parse Text to help with Get Subtext. If you would to catch up, each article references the previous article, so just work your way back to 5.0. Here is 5.2:

Let's first talk about Get Subtext. Here are the parameters:

  • Original Text: Typically you will use a text variable here
  • Start Index: Start of text OR Character position (this is where Parse Text can come in). Character position can also be a variable.
  • If 'start of text', we have length (at what character do we want it to end?) Length can also be a variable.
  • If 'character position' we have length in # of characters or 'end of text'. Length can also be a variable.

That's it. That is how simple it is. So, if I have a text of file names that are written in the following format: TheAccountName_123456789_123121.pdf, maybe I need to know just the account number to get this filed in the appropriate folder, or upload to an online document vault. I don't know the number of the starting character, because "TheAccountName" will change. If we are doing this in Excel, we need the left 9 characters of the right 20 characters, right. So what does that look like in PAD?

Well, the right 20 characters look like this:

No alt text provided for this image

Notice, we used %Variable1.Length% to get the total number of characters and subtracted all the characters we need from the right side to get our starting character number. Here is what getting the left 9 now looks like:

No alt text provided for this image

Lastly, could we skip a step? Theoretically, yes. In the first example, you could use Length 9, and that would skip the second step, taking you straight to the 'Left 9' starting a the 'Ending character - 20'.

What if the ending date wasn't fixed? What if it was 'TheAccountName_123456789_December312021.pdf? On our previous article, we could Split Text by the _(underscore) delimiter and get the result from %SplitText[1]%. For the purpose of this exercise, let's assume all of our account numbers start with "123". We can use that information to find the starting position of "_123" to determine where we want to start in Get Subtext:

No alt text provided for this image

Notice the 'Start Parsing at Position', so if you know, "I don't want to look for this in the first 15 characters," you can tell it to start at character 15. In this case, we want to start at the beginning, so we say 0. So, in this example, it found "_123" at position 14. This is a 0 based index, so the _is the 15th character, but it is position 14. It saved that position number as %Position%, so now I can use that in a Get Subtext action; don't forget to add 1 to get past the underscore:

No alt text provided for this image

Hopefully this information has been helpful and gives you some tips and tricks into extracting subtext from larger text items. Best of luck!

Michael Annis has no affiliation with Microsoft or its subsidiaries.?The “Best Practices” are purely compilations of his opinion and observations of conversations on the Power Automate Desktop User Community; an individual’s use of them should be taken as such.?Michael Annis has been using Robotic Process Automation (RPA) for over 2 years and maintains a “Top Solution Author” position on the Microsoft Power Automate Desktop User Community standings.?The best place for users to get their questions answered is through the User Community located here:?https://powerusers.microsoft.com/t5/Power-Automate-Desktop/bd-p/MPADesktop.

Peter McClellan

Accountant at BMI

1 年

Thanks Michael, This was extremely helpful on understanding how increase position count. Something so seemly simple yet this was the only place I found it described!

要查看或添加评论,请登录

Michael Annis的更多文章

社区洞察

其他会员也浏览了