cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Super User
Super User

More OData help - simple left() right() text parsing routines.

This is so easy in excel... why the h these guys use this odata garbage, I will never know... but I am trying to do something very simple, in thought.  Can someone help me write the odata routine that I can put into a Set Variable action?

 

Column: Filename = 123456-r1.pdf

 

I need to set two variables from this same basic filename structure.

 

Variable: PartNumber

Variable: Revision

 

Partnumber = 123456 (all of the numbers up to and not including the "-")

 

Revision = 1 (the one or two digit number between the "r" and the ".")

 

In excel, I would write:

(A1)=123456R-r5.pdf

(A2)=SEARCH(".pdf",A1) = 11

(A3)=SEARCH("r",A1,A2-3) = 9

PartNumber=LEFT(A1,A3-2) = 123456R

Revision = MID(A1,A3+1,A2-A3-1) = 5

 

It would likely take me two full days to figure out all of the syntax required to do this simple task.  I beg for help from anyone that has some sympathy for my plight!

 

Thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: More OData help - simple left() right() text parsing routines.

Ok, it took a bit less time than I expected.  Lucky this time.  Forunately, expression builder is more advanced than I thought.  It is still cryptic as hell.  I was blown away by the inability to do simple add/sub.  Had to wrap add() or sub() around things to do that.  wow...  What saved me wsa the lastIndexOf function.  The ability to search form the right made it much easier.

 

To find the last "r", I used Set Variabe "Find-r":  

lastIndexOf(body('Get_file_metadata')?['Name'],'r')

 

 To find the last ".", I used Set Variable "Find Dot":  

lastIndexOf(body('Get_file_metadata')?['Name'],'.')

 

To get part number, I wrote: 

substring(body('Get_file_metadata')?['Name'],0,add(variables('Find-r'),-1))

 

Toi get the revision number, I wrote: 

substring(body('Get_file_metadata')?['Name'],add(variables('Find-r'),1),sub(sub(lastIndexOf(body('Get_file_metadata')?['Name'],'.'),lastIndexOf(body('Get_file_metadata')?['Name'],'r')),1))

 

View solution in original post

2 REPLIES 2
Super User
Super User

Re: More OData help - simple left() right() text parsing routines.

Ok, it took a bit less time than I expected.  Lucky this time.  Forunately, expression builder is more advanced than I thought.  It is still cryptic as hell.  I was blown away by the inability to do simple add/sub.  Had to wrap add() or sub() around things to do that.  wow...  What saved me wsa the lastIndexOf function.  The ability to search form the right made it much easier.

 

To find the last "r", I used Set Variabe "Find-r":  

lastIndexOf(body('Get_file_metadata')?['Name'],'r')

 

 To find the last ".", I used Set Variable "Find Dot":  

lastIndexOf(body('Get_file_metadata')?['Name'],'.')

 

To get part number, I wrote: 

substring(body('Get_file_metadata')?['Name'],0,add(variables('Find-r'),-1))

 

Toi get the revision number, I wrote: 

substring(body('Get_file_metadata')?['Name'],add(variables('Find-r'),1),sub(sub(lastIndexOf(body('Get_file_metadata')?['Name'],'.'),lastIndexOf(body('Get_file_metadata')?['Name'],'r')),1))

 

View solution in original post

Super User
Super User

Re: More OData help - simple left() right() text parsing routines.

Nice solution... thank me very much!! 😄

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 381 members 6,164 guests
Please welcome our newest community members: