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

Trim String

I have the following text string

 

@[8,0CF25058-55D2-E811-8145-5065F38B02E1,"Jane Doe"] @[8,033D8C19-0EEB-E711-810E-5065F38B02E1,"John Smith"] What does this look like when the text is added to a note?

 

I want to remove parts of the string to make easier to read. There could be any number of items to remove but the format will be the same. This one would ideally result in the following. 

 

Jane Doe John Smith What does this look like when the text is added to a note?

 

If the original text string looked like this. 

 

@[8,0CF25058-55D2-E811-8145-5065F38B02E1,"Jane Doe"] What does this look like when the text @[8,033D8C19-0EEB-E711-810E-5065F38B02E1,"John Smith"] is added to a note?

 

Result should be the same. 

 

Jane Doe What does this look like when the text John Smith is added to a note?

 

Please help

1 ACCEPTED SOLUTION

Accepted Solutions
Dual Super User
Dual Super User

Re: Trim String

Hi!
The kind of scenario that can be solved with regex easily and takes hours to find out a good solution in WDL 😋

EDIT: I had finally the chance to test it, fixed some errors, now working!

 

Let's assume you store your input string in a variable called 'myInputString'
I would do the following
Create a variable called 'myOutputString' type string
Create an aux variable, let's call it 'auxArray' type Array, assign as value the following expression:

 

split(replace(replace(variables('myInputString'),']','] '),'@',''),'[')

 


Then I would add an Apply to Each, using variable 'auxArray' as its input.
Inside the apply to each:

-add a Condition, select 'contains':

on the left side add the expression

 

item()

 

on the right side add the character ]

 

Now, on the true branch of your condition:

- add an Append to string variable: name myOutputString, assign as value the following expression:

 

split(item(),'"')[1]

 

-add a second Append to string variable: name myOutputString, assign as value the following expression:

 

split(replace(item(),']',''),'"')[2]

 

 

Now, on the false branch of your condition:

-add a third Append to string cariable: name myOutputString, assing as value the following expression:

 

item()

 


After the Apply to Each, add a dummy Compose action block, assign as its input the variable 'myOutputString'. Execute the flow and inspect dummy Compose contents

 

Flow_regex.png

Here you are the results with both examples you provided:

 

Jane Doe John Smith What does this look like when the text is added to a note?

Jane Doe What does this look like when the text John Smith is added to a note?


Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

5 REPLIES 5
Dual Super User
Dual Super User

Re: Trim String

Hi @cholst 

 

Continuing to your post from here: https://powerusers.microsoft.com/t5/General-Power-Automate/Get-Value-s-from-text-string/m-p/491472#M...

 

Once, you have individual items, you can use another split to split on the GUID at the , so for a string like: [8,0CF25058-55D2-E811-8145-5065F38B02E1,"Jane Doe"]  It will return you with three items. you can then access the last one "Jane Doe"] and use the replace function to replace the " and ]. 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Dual Super User
Dual Super User

Re: Trim String

Hi!
The kind of scenario that can be solved with regex easily and takes hours to find out a good solution in WDL 😋

EDIT: I had finally the chance to test it, fixed some errors, now working!

 

Let's assume you store your input string in a variable called 'myInputString'
I would do the following
Create a variable called 'myOutputString' type string
Create an aux variable, let's call it 'auxArray' type Array, assign as value the following expression:

 

split(replace(replace(variables('myInputString'),']','] '),'@',''),'[')

 


Then I would add an Apply to Each, using variable 'auxArray' as its input.
Inside the apply to each:

-add a Condition, select 'contains':

on the left side add the expression

 

item()

 

on the right side add the character ]

 

Now, on the true branch of your condition:

- add an Append to string variable: name myOutputString, assign as value the following expression:

 

split(item(),'"')[1]

 

-add a second Append to string variable: name myOutputString, assign as value the following expression:

 

split(replace(item(),']',''),'"')[2]

 

 

Now, on the false branch of your condition:

-add a third Append to string cariable: name myOutputString, assing as value the following expression:

 

item()

 


After the Apply to Each, add a dummy Compose action block, assign as its input the variable 'myOutputString'. Execute the flow and inspect dummy Compose contents

 

Flow_regex.png

Here you are the results with both examples you provided:

 

Jane Doe John Smith What does this look like when the text is added to a note?

Jane Doe What does this look like when the text John Smith is added to a note?


Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

cholst Helper I
Helper I

Re: Trim String

Thank you for thoughtful answer. I’ll test it out. Similar if I only wanted to keep items between the [] is it similar and just as easy?
Dual Super User
Dual Super User

Re: Trim String

Hi!

Haven't tested yet but I guess If you want to keep just 'Jane Doe John Smith', then for sure you need to remove the 'Append to array' on the False branch of your condition and... probably do little modifications on the true branch

Hope it helps


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
cholst Helper I
Helper I

Re: Trim String

very close. In this example

@[8,0CF25058-55D2-E811-8145-5065F38B02E1,"Jane Doe"] What does this look like when the text @[8,033D8C19-0EEB-E711-810E-5065F38B02E1,"John Smith"] is added to a note?

I would want the end result to be 

[8,0CF25058-55D2-E811-8145-5065F38B02E1,"Jane Doe"] [8,033D8C19-0EEB-E711-810E-5065F38B02E1,"John Smith"] 

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Users online (5,911)