cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bsa1975
Level: Power Up

Extract Information from a String

Anybody an idea how to extract informations from a string?

 

My String looks like follow:

"OELGA ON LOWG 01/26 0127Z ON RPT DEP: LOWW - 4 VIENNA DEST: LOWG - GRAZ"

 

The following function finds "DEP:" in the string but takes the 4 Digits form the beginning of the string.

Output: "ELGA"

I would need the 4 Characters after the found "DEP:"...

utput should be: "LOWW"

if(contains(body('Html_to_text'), 'DEP:'),substring(body('Html_to_text'),1,4),'')

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Extract Information from a String

Hi @bsa1975

 

Your substring function is returning a string beginning at index 1, which is the 2nd character (the first character has an index value of 0), hence you're getting ELGA. So what you want to do is find a way for the substring to begin just after 'DEP:'

 

Here's a function that should work for you:

if(contains(body('Html_to_text'), 'DEP:'),substring(body('Html_to_text'),add(indexOf(body('Html_to_text'),'DEP:'),5),4),'')

 Here's what this does, reading sort of from the inside of the expression outward:

indexOf(body('Html_to_text'),'DEP:') finds the index location of the beginning of the DEP: string (which I'm assuming would only occur once). In your sample string, that index would be 33.

add(....,5) adds 5 to that index number, because you want the string which begins after DEP:[space]  - In your sample that's 38.

substring(body('Html_to_text'),...,4) returns a string from your input string which begins at index 38, and returns 4 characters, hence in this case LOWW.

 

Does that make sense...? I hope this will help you with using string functions in general - they're quite powerful!

 

Sandy



Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!


View solution in original post

2 REPLIES 2
Highlighted
Super User
Super User

Re: Extract Information from a String

Hi @bsa1975

 

Your substring function is returning a string beginning at index 1, which is the 2nd character (the first character has an index value of 0), hence you're getting ELGA. So what you want to do is find a way for the substring to begin just after 'DEP:'

 

Here's a function that should work for you:

if(contains(body('Html_to_text'), 'DEP:'),substring(body('Html_to_text'),add(indexOf(body('Html_to_text'),'DEP:'),5),4),'')

 Here's what this does, reading sort of from the inside of the expression outward:

indexOf(body('Html_to_text'),'DEP:') finds the index location of the beginning of the DEP: string (which I'm assuming would only occur once). In your sample string, that index would be 33.

add(....,5) adds 5 to that index number, because you want the string which begins after DEP:[space]  - In your sample that's 38.

substring(body('Html_to_text'),...,4) returns a string from your input string which begins at index 38, and returns 4 characters, hence in this case LOWW.

 

Does that make sense...? I hope this will help you with using string functions in general - they're quite powerful!

 

Sandy



Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!


View solution in original post

bsa1975
Level: Power Up

Re: Extract Information from a String

Sandy, 

thank you. That works great!

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 (Last 30 Days)
Users online (4,931)