cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

Help needed to extract substring with variable length

Hello masters,

 

I am totally new to Microsoft Flow and I have been trying my luck to get started with it to complete a sample task automatically.  I have sent an bulk email to all my customers requesting them to register for the webinar.  Once they register I get an automated email from system in html format.  I am trying to build a flow to get their details and put it in a excel online list which is stored on my onedrive for business. 

 

  1. Trigger and Data Connections worked well.  
  2. I also managed to convert the email body to text from its original html format using Html_to_text step.
  3. I managed to store that converted plain text into a variable called 'EmailBody'

From the above step onwards the issues starts, I have got an information in following format:

 

Webinar registration (webinar_reg-bah)

Company : <Customer Business Name>

Name: <Customer Full Name>

Email: xxxx@xxx.xxx.xx

phone: xxxxxxxx

position: <Designation>

 

I need help to extract the exact information from above and put it in the appropriate columns in the excel table.  Since I do not know exact length of strings I am unable to define it in any numeral form.

 

Any help on the above issue is highly appreciated.

 

Thank you

 

Kedar

2 ACCEPTED SOLUTIONS

Accepted Solutions
Dual Super User III
Dual Super User III

Re: Help needed to extract substring with variable length

AS an example, here are the formulas to extract the Company Name. Each one goes in its own variable or Compose action.

//Returns the starting position of the Company Name
add(indexOf(variables('InputText'),'Company :'),9)

//Returns the length of the Company name
sub(indexOf(variables('InputText'),'Name:'),outputs('Compose'))

//extracts and trims the company name from the overall text.
trim(substring(variables('InputText'),outputs('Compose'),outputs('Compose_2')))

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Highlighted
Dual Super User III
Dual Super User III

Re: Help needed to extract substring with variable length

1) use this instead

add(indexOf(variables('InputText'),'Company :'),length('Company :'))

2) You could probably figure out a way to use looping.  But then you have to also figure out how to change the pattern being searched for in each loop iteration.

3) For the last line simply use the length of the total string in place of the lastIndex of the next label.  The numbers change, but the pattern is the same.  Look for what you know precedes and follows the string and then use that to figure out dynamically where each string starts and stops. 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

8 REPLIES 8
Highlighted
Dual Super User III
Dual Super User III

Re: Help needed to extract substring with variable length

In PowerApps I've done this kind of thing using Match() and a REGEX expression.  But Flow doesn't have a REGEX expression at this point.  So the next best thing is to use IndexOf to find where the Labels are in each line.  Then use Substring and the differences between each label to extract the text that falls between the end of one label like 'Name:' and the beginning of the next like 'Email:'



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted
Helper I
Helper I

Re: Help needed to extract substring with variable length

Hello sir

Whatever you mentioned May be that is the right solution but i need sample code. Because as i mentioned i am totally new to flow and do not know anything about expressions in flow.

Hence it would be great if you can provide me sample code.
Highlighted
Community Support
Community Support

Re: Help needed to extract substring with variable length

Hi @kedarsk,

 

Maybe this post could help you something:

https://powerusers.microsoft.com/t5/Building-Flows/Extract-text-from-Body-of-an-email-in-Flow/m-p/51... 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Highlighted
Helper I
Helper I

Re: Help needed to extract substring with variable length

Hello support team

 

Thank you for the link.  However, that did not answer my question either.  I could see in that link some of the examples but all of them had the indexOf parameter define by numbers.  In my case, I do not know at which position it will be exactly hence I need to figure it out dynamically.

 

Further as I mentioned in all my posts.  I am a total new to Microsoft Flow concepts.  Therefore, I have prior little experience of PowerShell scripting and Excel Formulas with VBA.  Beyond this my understanding about programming is at very basic level.

 

Hence, appreciate if someone can provide me some visual / spoon fed techniques to achieve my goal and encourage my interest in learning more about Flows.

 

Thank you

Dual Super User III
Dual Super User III

Re: Help needed to extract substring with variable length

AS an example, here are the formulas to extract the Company Name. Each one goes in its own variable or Compose action.

//Returns the starting position of the Company Name
add(indexOf(variables('InputText'),'Company :'),9)

//Returns the length of the Company name
sub(indexOf(variables('InputText'),'Name:'),outputs('Compose'))

//extracts and trims the company name from the overall text.
trim(substring(variables('InputText'),outputs('Compose'),outputs('Compose_2')))

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Highlighted
Helper I
Helper I

Re: Help needed to extract substring with variable length

Hi @Pstork1 

 

You are awesome man!  The solution worked for me initially.  I appreciate for your detailed explanation by comments which helped me to understand the flow of the proposed solution.  However, to mark it as accepted solution, I just need following information:

  1. I noticed that you have put number 9 which is the length of  'Company : '.   However, can we calculate it dynamically instead of manually putting 9?
  2. If we do it this way then, I will have to write the same lines of code for each and every detail that I want to extract from email so I might end up writing this code for 7-8 times since there are that many details.  Can we use looping instead of manually writing down this code?
  3. The code will work fine until the last line however it will fail at the last line as we are calculating the starting position of the first field and then subtracting that number from the start position of another field.  In this example for field on the last line there will not be any other line to subtract the value from.

Appreciate your clarification on the above.

 

Regards

Kedar

Highlighted
Dual Super User III
Dual Super User III

Re: Help needed to extract substring with variable length

1) use this instead

add(indexOf(variables('InputText'),'Company :'),length('Company :'))

2) You could probably figure out a way to use looping.  But then you have to also figure out how to change the pattern being searched for in each loop iteration.

3) For the last line simply use the length of the total string in place of the lastIndex of the next label.  The numbers change, but the pattern is the same.  Look for what you know precedes and follows the string and then use that to figure out dynamically where each string starts and stops. 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Highlighted
Helper I
Helper I

Re: Help needed to extract substring with variable length

Hello brother

Can you please help me for looping code? Also i had a question about how will it be if we can store it in an Array instead of using normal compose action? I think with array we can use loops.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors
Users online (6,853)