cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DrinkWater
Level: Powered On

Find a string and put letters before and after.

Hi All,

I was able to count strings based on what I heard here.

https://powerusers.microsoft.com/t5/Building-Flows/Can-Microsoft-Flow-count-strings/m-p/324770#M3501...

Thank you very much.

 

I could do something I wanted to add.

When I find the letter "abc", I want to concatenate the two letters before and three letters after that letter.

(String)

 

Spoiler
asfweabcgfrthoabcopfgrkpabchjk

(String to retrieve)

 

Spoiler
Spoiler
eabcgfr
hoabcopf
kpabchjk

 

Every time I find it, I want to write a string to my email.
In the way of the image, the same character is taken out many times.

test.PNG

I want to write the extracted strings one by one to the mail.

Can you repeat the letter extraction using "Do Until"?

 

Kind Regards.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Find a string and put letters before and after.

Hi @DrinkWater 

I think I have managed to get to the solution that you are after.

In my example I have set a variable as your string but you would just need to change this to be your input value.

 

Initialise 3 variables for the following

TestString - the string that we want to process

TEMP - a temporary holding string (you'll see why later)

StringArray - to hold the values we pull out of TestString

 

chrome_2019-07-22_17-26-34.png

 

Then we create a Do Until action. Set the properties of this to 

indexOf(variables('TestString'),'abc') is equal to -1

When the indexOf function cannot find the string 'abc' it will return a -1 and then exit the loop.

Within the loop you then want to add an Append to array variable action. The variable we will append to is StringArray and you will need to set the value to 

substring(variables('TestString'),sub(indexOf(variables('TestString'),'abc'),2),8)

This will put out the first instance of "abc" with the 2 characters before and the 3 after (8 character length)

Finally, using a Set variable action, set the variable TEMP to the value 

substring(variables('TestString'),add(3,indexOf(variables('TestString'),'abc')),sub(length(variables('TestString')),add(3,indexOf(variables('TestString'),'abc'))))

This will set it to everything in the string TestString minus the part we just extracted. You then need to set TestString to the value in TEMP. We have to do it this way as we are not able to set TestString to an expression that references itself.

 

chrome_2019-07-22_17-27-15.png

 

As this loops, the value of TestString will get shorter and shorter until there are no instances of 'abc' left.

Last step is to use a Join action to join the contents of your variable StringArray using HTML (such as <br> ). Then you simply include the output from the Join action somewhere in your email at the end of the process.

 

chrome_2019-07-22_17-29-37.png

 

Hope that all makes sense.

 


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

Proud to be a Flownaut!


4 REPLIES 4
Highlighted
Super User
Super User

Re: Find a string and put letters before and after.

Hi @DrinkWater 

I think I have managed to get to the solution that you are after.

In my example I have set a variable as your string but you would just need to change this to be your input value.

 

Initialise 3 variables for the following

TestString - the string that we want to process

TEMP - a temporary holding string (you'll see why later)

StringArray - to hold the values we pull out of TestString

 

chrome_2019-07-22_17-26-34.png

 

Then we create a Do Until action. Set the properties of this to 

indexOf(variables('TestString'),'abc') is equal to -1

When the indexOf function cannot find the string 'abc' it will return a -1 and then exit the loop.

Within the loop you then want to add an Append to array variable action. The variable we will append to is StringArray and you will need to set the value to 

substring(variables('TestString'),sub(indexOf(variables('TestString'),'abc'),2),8)

This will put out the first instance of "abc" with the 2 characters before and the 3 after (8 character length)

Finally, using a Set variable action, set the variable TEMP to the value 

substring(variables('TestString'),add(3,indexOf(variables('TestString'),'abc')),sub(length(variables('TestString')),add(3,indexOf(variables('TestString'),'abc'))))

This will set it to everything in the string TestString minus the part we just extracted. You then need to set TestString to the value in TEMP. We have to do it this way as we are not able to set TestString to an expression that references itself.

 

chrome_2019-07-22_17-27-15.png

 

As this loops, the value of TestString will get shorter and shorter until there are no instances of 'abc' left.

Last step is to use a Join action to join the contents of your variable StringArray using HTML (such as <br> ). Then you simply include the output from the Join action somewhere in your email at the end of the process.

 

chrome_2019-07-22_17-29-37.png

 

Hope that all makes sense.

 


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

Proud to be a Flownaut!


DrinkWater
Level: Powered On

Re: Find a string and put letters before and after.

Hi, @LeeHarris 

 

Wow! Thank you for teaching me.

 

I want to understand the content.

So I try one by one what is written.

 

"Do Until action" is doing strange movement.

Every time I repeat 60 times somehow.

 

Because I can not debug, I can not understand what is happening.

 

indexOf(variables('TestString'),'abc') is equal to -1

This expression can not be put into the condition as it is.

0.PNG

 

I have entered expression this way.

Am I wrong like this?

00.PNG000.PNG

 

Sorry to bother you again.

Thanks.

Super User
Super User

Re: Find a string and put letters before and after.

Hi @DrinkWater 

The way that you have entered the do until expression in your last screen shot is correct. If the loop is repeating 60 times still then it is reaching its maximum executions. Check the variable (currently called TestString) that you are storing the initial string in to make sure that this is not blank.

In terms of debugging, if you are able to execute the Flow then you can check the historic runs via the Flow details screen. From here you can see information on properties/inputs/outputs etc at each step of the process.

 

2019-07-23_14-39-34.gif

 


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

Proud to be a Flownaut!


DrinkWater
Level: Powered On

Re: Find a string and put letters before and after.

Hi, @LeeHarris 

 

Thank you for teaching me so kindly.

There was a part where I set the variable incorrectly.

 

I was able to realize what I wanted.

I appreciate it!!

 

 

This thread is now closed.

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020

thirdimage

Flow Community User Group Member Badge

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

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 Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 215 members 4,736 guests
Please welcome our newest community members: