Remove unwanted characters from String in Power Automate or Logic Apps Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi there folks in today's demonstration I'm going to show you how you can remove unwanted characters from a string in power automate using one action so no apply to each no variables a very very simple way to remove unwanted symbols or numbers from an existing string so if that's something that interests you please make sure you like And subscribe and without further Ado let's jump into the demonstration so I'm going to kick things off from a manually triggered flow and in order to to accept an input string I'm just going to add in an input parameter here and we can call this string of course your string can come from anywhere within the flow but this really makes the demo easy for me today I'm going to add in an action first up that is going to enable me to store a string of symbols and characters that I want to remove from the string that I provide to this flow so I'm going to remove all of the symbols from the top of my keyboard here I'm going to ask it to remove all of the numbers 1 2 3 4 5 6 7 8 9 and zero and I'm also going to go for vows as well so a e i o u and you'll note that I'll put these in twice both upper and lower case because what I'm going to show you is case sensitive so we need to make sure we cover both upper and lower so the aim is to remove um these unwanted characters or potentially keep these unwanted characters depending on what your use case is but this demonstration will show you how to both handle keeping and dropping the character that are in this string so next up all I'm adding is a select and this pretty much is the end of the demo uh all you need for this process is a select and the input to a select needs to be an array so an array is of course based on those square brackets at the moment I have a string which is not an array but I can use an expression called chunk and what chunk will do is it will take a string or in fact another array and it will chunk it into smaller arrays but because we're passing in a string here and if I set the second property as one it'll actually turn the string that I provide to this flow into an array of characters and we'll have a look back at that in the history to understand that in a bit more detail so by chunking that string into an array what we can do now is toggle this select into text mode and we can actually just use a condition so again into the expression editor there is a condition called contains and contains will look at both an array or a string to see if the value that you provide as the second property is contained within that string or array so with the dynamic content if I insert this unwanted characters compose output and then compare it against item item of course is each of the individual characters of that string because I've chunked that string into an array and that's what ultimately item refers to is each object or value within a an array so by doing so we'll get a true or false is that value contained within that string if it is we'll get a true if it's not we'll get a false and I would be at this point looking to wrap this in an if statement but I'm going to add this expression as it is and save and test and we can have a look at the output in order to understand why it works so as I test the flow it's going to ask me for an input string and remember it's going to remove the vowels so the a the O of Deo bird and also it's going to remove numbers I'll put 365 but also symbols so I'm going to put some of these symbols in amongst this string so that we can see them being removed as I as I run this I'm also going to copy the string so I can reuse it so if I run this now what will happen is we will get an output from the select of trues and falses and we can now see that on screen so where we've got no match we have a false as you can see here D is not in our original string but where the letter A which is a vow exists we have a true and similarly for that exclamation mark Cuz I added all the symbols again we have a true the lower case m is not a vow or one of the symbols or a number so we have false and we can use this logic to our advantage to either return the letter that's in this existing array or to replace it with nothing and so that's exactly what we're going to do now when we edit the flow so back into this expression I'm going to go to the start of our contain and I'll insert an if and so that's going to check if something is true or false if it is true then we're actually going to Output nothing in this case two single quotes if it's not true then we are going to Output the item and so this will enable us to create an array of either the values we want to keep or empty values where we don't want to keep and if your requirement was different if you wanted to keep the characters within this string then you'd simply Swap this round rather than having your double single quotes for the true you would have item as true and then the double single quotes for the false so I'll go ahead and update this and just to complete the flow if I go and add in another action we can return the completed expression and we can do that using a join expression and so all join will do is it will take an array in this case our select which is all of our individual characters and we're going to join that based on nothing which is single quotes and if I add that we can save and test and we'll have an updated string so with the flow and test if I paste in that similar expression from before what we're hoping for is for this to drop any of our vowels any of those symbols and also those numbers so actually we should just end up with dmbr Rd hopefully so if I run that flow and if we look at the new string we can see we have as an output dmbr D we've removed the valves we removed the symbols and we've remove the numbers if we have a look at the select we can see the input which is our chunk of that string that I provided and then we can see in the output where the condition is false we are keeping that character where it's true we are just simply inserting nothing and when we do do the join we actually remove these nothings to create a string that does no longer include those unwanted characters from our compose now if your requirement was slightly different if we go back into Ed it if we think about this select statement and this if expression this if is based on a true false condition so if something contains it's true if it doesn't it's false now there's also other opportunities to use expressions like is int so if a value is an integer we could actually just keep all of the numbers so again if we apply the same logic with is in on item we can check to see if there is a number if there a number it's true then we can drop it otherwise we can keep it but if we swap this logic round as well and if I move these single quotes to the end of the expression like so what will happen is we'll actually keep the numbers rather than dropping the numbers because we've reversed the true false logic here with the item to keep or to drop so without using a compose we're able to use this isint expression to check if the value within this item is an integer if it is then we're going to Output that value if it isn't then we're going to return nothing and so what we'll do when we test this we should get the numbers back 365 so with the flow and test mode if I paste in that string from before we should hopefully get the output of the numbers 365 and if I pop open that composed string we can see there in the outputs I have just the integer values from that original string if we look at the select again those chunked individual characters and then if we look through the output here we can see everywhere that there's no match we've inserted an empty value and where there is a match we've kept that value by using the expression item now this would be particularly handy If you're receiving alpha numeric strings with numbers in them and ultimately all you want to do is keep the number very quick very efficient and as you can see it's simply one action just to remind ourselves it's the select based on a chunk we Chunk Up that string whether that's a subject and an email address or any other string from a Microsoft form Etc and we chunk it into one siiz chunks which gives us that array and by chunking it up we can then use this simple if expression based on a true or false in this case we're looking at an integer previously we were using contains and then depending on whether or not you want to keep it or drop it we just simply reverse these two values if you're looking to keep it if it's true then you have item if you're looking to drop it when it's true you move move the item property to the false value of our if statement and that's all there is to it so I hope you've enjoyed that i' would love to hear how you might use that in your own flows and if you've got any ideas for future videos please make sure you leave me a message and I'll have a look and see what I can do so thanks very much for watching and I look forward to seeing you again sometime soon cheers
Info
Channel: DamoBird365
Views: 1,918
Rating: undefined out of 5
Keywords:
Id: _6f5UBpHhZ0
Channel Id: undefined
Length: 9min 43sec (583 seconds)
Published: Sat Mar 23 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.