String Functions in Power Automate - Beginners Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's create a flow and start working with functions we will just click create and choose an instant cloud we will give our flow a name and here I will call mine string functions and choose to manually trigger hello create the data for the exercise today will be the same and we will apply a lot of string functions on this data go to the course page the link is in the description below here you'll scroll a little bit down to description and take the first value which is this Ctrl C copy it then go to Power automate here I'll click new step and I will choose an initialize variable this variable will be called our text first path so let's just rename this so we can also see what's going on so our text first part we will be giving it the same name so our text first part it will be of the type string and in the value I'll simply just Ctrl V paste it in we have our first variable let's make a second one which will be the second and last one for this flow so here one move we name this to our text second art and again here I can just copy it here I have nothing in my clipboard it will also be of the type string and the last part the value here that will be in the course page as well it will be this thank you very much like this Ctrl V it in and I can save my flow first of all I want to concat these two together and we'll use the concat function it's a short for concatenate and it looks like this so I click new step and then I'll find a compose here it is and you can use this function in all kind of power automate actions we'll just use them in simple composers but again try to apply them everywhere they're very useful I go in here and to get to the expression I need to toggle this one over to expression first of all let's talk a bit about how we can actually refer to this variable up here and we will do so by saying variables then the parentheses and single quotation marks then we give the name of that variable so this one will be our text first art like this this will refer to the first variable and let us just Mark everything Ctrl X we have it on our clipboard now we want to take the first variable take the second variable concatenate that means that they will come next to each other to do so we will use the concat function a parentheses here we need the first text and this is exactly what we have in the clipboard so I control V now we refer to the variable our text first path so we will get the value of that and we will concat it with the our text second part a mega comma here Ctrl V so now we are concatening the same variable in but we will of course just change our text first to our text taken path like this what I recommend always do when we write these Expressions is Ctrl a control C you have it on your clipboard because sometimes they disappear and you can see they even says that it's invalid this is a known power automate bug it only does it the first time so now when I click it the second time it will not do it let's also rename this compose so I click the three dots take rename and here I'll call this one concat and we can save and test right see that we can concatenate these two variables together like this and if you go into the log to the compose concat you can see Mr and Mrs thirst we have number four Private Drive we're proud to say that they are perfectly normal thank you very much by the way if you know where this comes from please let me know in the comments below this is one of my favorite books anyway we have a lot of things to do so let's click edit and introduce a new function say that I want a private Drive printed out of this one up here then I will need to say I refer to our text first path and then I'll give an index it will look like this so the index of this and now we have to count but that will be since it's zero indexed the first position is zero that is where we are now I'll say 0 1 2 3 4 5 6 7 8 9 10 11 12. 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 so this is the position 37 or the index and we'll go down here and find a compose this one we will call compose substring always rename your activities I know I will say this a lot during these exercises but so important we can see what's going on especially now in our flow since we will have a lot of composers when you and your colleague come back you can easily see what these composers are about we go down here so now we will also go to expression and here we will use again we will use the variable our text first path we will not use the our text second part what we will do here is to find the substring function like this then we will say parentheses and here you can see we actually guided we need a text and that is indeed our variables parentheses and then the variable name so that will be our text first path this is a very good exercise we will repeated a lot so please do it after me in power ultimate and not just passively watching so this is our text then we can have a comma and then we can have the start index that is where we want to start and since we wanted the private drive out we can say 37. you can also put an optional length length to this but I think what we will do here is to control a Ctrl C we run it now and then we will apply it in the next run again it will say it's invalid it's not it's a known bug in power automate and here you can see we have it so I'll click test save and test and we will run our flow if you go to the compose substring you can see that we're actually starting at private drive now but imagine that we only wanted the private drive out then we wanted to say well this is [Music] um this is one two sorry one two three four five six characters we can specify the length of erm what we want to print out in the actual substring function let's just pick privet and what we'll do here is to click edit and go inside it here and what you do is to go after the 37. have a comma and here you can see we can have a length I'll just do a six and now Ctrl a Ctrl C to copy it just to make sure it's in the clipboard because when I click update here it's not now you can see it didn't update so what you will do here is to delete it go into the expression Ctrl V and we have it that's one of the issues that we have to face is power automate developers is that we have minor blocks here but it's not really a lot you'll get used to it and the program is so amazing so yeah stay tuned now you can see we have printed the private out so sharpstring is an excellent way of taking characters out of a string if you know the position where we want to do it we can do another nice thing is the slice this is an improvement to the substring and let me just show you how it works so I click edit take a new step and I'll do another compose this one will be compose slice here like this and we will still refer to the our text first part as the variable so let's do an expression and here as I told you we wanted to look at the slice it does almost the same as substring but it is a little bit more advanced and when I say Advanced we can use it in a few more cases here I need a text again and we practice it so say variables and in case you want to finish this you could see that when I write VA the variables come up simply just press tab it will auto complete then we have a parentheses a single quotation marks and now we give the name of our variable our text first path this is what we're looking at then we go outside here we'll have a comma now we need a start index we will use the start index just as before so here I can say 37 and a comma and now we need an end index before we needed a length that was 6 and here we just say 43 again Ctrl a Ctrl Z Market click ok there you go now save and test run the flow these ones are of course really fast because those are just um compose strings where we just work with data inside power automate there you go we now have the same results but we can also see let me just do this I'll have a new step let me do a compose once more I just want to show you what the slides can also do slice two and here again I'll go into the expression here I'll do a slice the text that will be variables let's train it let's keep doing this until it sticks it will trust me when you have done this throughout the video and when you finish that you will know how to write these functions very well it's not complicated at all anyway we have our variable here then we can actually say we want to start at -6 and that will go because the start index is zero at the at the start of the variable then we go negative that is we take from the end let me show you so I'll just Ctrl a Ctrl C I'll click OK here we will save and test let's go do it yeah so the slides to you can see that now we got normal out and that is because if I go up to my text that is because we have normal here the end so um we can do a few more things with the slides now I want to introduce you for a function that I do use a lot which is the replace big new step find the compose let's say that I want to change the name of this our text first part I want to replace the dursely to Jensen so again let's just rename it down here so I will find a what it is compose replace I'll go into the input and here I will pick an expression and what I want to do here is to find the replace and now I have a parenthesis we'll need a text that we will look at then we will look for something and we will tell power automate all this from replace function what we want to add instead let's do it one step at a time so here I need to have the variables parentheses single quotation marks we again need to refer to the our text first path and now you can see here my expression disappeared that's fine we'll just added again so another excuse for practicing these things so this one will be our text first part then I want to say I want to look for something and this one needs to go with the new thing I add here I want to look for Thursday so I'll in single quotation mark I specify the string to look for remember to spell it right otherwise we can't find anything then I'll have a comment and then I'll say what do I want to add in instead or replace I'll have it here in single quotation marks Ctrl a control C mark it again click ok here we have our replace let's try to run it in the compose replace you can see Mr and Mrs Jensen of number four now we have replaced it and this is a very useful function I also want to show you the two upper and if I go into new step and you know the drill just find a compose you will rename it to to Opera and we will go into the input go to expression and here the reason why we do this is that we often get data from different kinds of systems and when we just want to compare the characters regardless of if they are over or lowercase then we will convert I both these two to uppercases or lower cases and then we can compare it looks like this so I'll say two other and then I want to have my text which were in the variables here our text first part Ctrl a control C you will get used to this and you can see it's uh it can be annoying that each time this block accuse it's always the first time but you can use and some days it's not there just you don't do anything wrong it's just the way power automate is at the moment here you can see that is all uppercases we can also do a to lower but I will leave that to you because it works exactly like what we did now I could get it we can also try to search for something with the index off say I want to search for a number here in this one here then it will give me the start index of number if I start doing that so I'll have a new step find a compose yeah and this one will be compose and then we will say index off so here will have an expression and what we just do here is that we'll say index of then we want to have a text tool again and again we will just use the same so our text first path then we will have a comma and we want to search for something remember to put it in single quotation marks yeah I will search for normal control a control C click ok and do this so now let us just do this and let's see if we can find it so if I go to the index off we can see that a normal R in position 94. um the stat looks right we go up here and it does not really and that is because we have the normal here and I I think I accidentally said number but I I I meant normal and I also used normal down here so 95 is the right thing I hope you enjoyed these videos you'll see me make some smaller errors here but what I meant was the normal thank you let's also change this to we can find the nth index off so if you look in this one up here you can see that we are having the Mr we're having them twice we're having it here and here I know that this is says Miss in the second one but we can actually say I want the first occurrence of it the second one the third one that doesn't really exist but we could try it so let's find a new compose this and I'll find in index off so compose end index off let's go try that so we will make an expression and here I will find the nth index of if I render this and you can see it guides us pretty much true again we also use the same but uh our text first path now we'll have a comment now let's try to look for Mr with a capital M like this and here we will have the occurrence so um I'll just say one that will be the first occurrence this will be equivalent to the index of index of text the first occurrence also so we literally just wrote the same with different functions here Ctrl a Ctrl C click ok test save and test like here and now you can see the nth index is as index 0 that's because our text staff with m r you can also let me just click edit here let's try to change it and if I go into my expression let's change it to the second location occurrence so I change one two two Ctrl a Ctrl C update and now you will see this didn't update and again it's uh kinda annoying when this happens but uh right now we will have it so the solution is often just to delete your function and then add it again with whatever you changed in it yeah I changed one to two and now we are running it and again here you can see that what is supposed to run smoothly that was it just took some seconds here we have the end index and now we have the index eight and again this was because it's index 8 here index 0 here index 8 here then we can start to we can also introduce the last index off so if I say new we were composed and I really hope you will do these things and start to use them in your flow you will learn a lot about writing functions so the strings function functions is a great introduction to functions because those ones are the most used ones and they're easy to understand then we go in here now we go into expression I'll say last index of and we'll have a text I have the variables hour text first Heart Like This and then let's try to look for Mr again and here you don't need an index this because we will find the last index so we will look for Mister and then we will take the last index off so I'll control a control C and let me just click OK here and we have it and again you have to check here and there that's just unfortunately how it is at the moment but I heard rumors that power to mate wanted to upgrade on this you can see we have the eighth and this is the opposite of the index of index of takes the first occurrence where last index of takes the last occurs so these ones work almost like the same but they pick the first element and the last element so here we have it at index 8. we can also have a if we want to check what a certain string starts with then we can have a true or false we can say does this start with Mr then we want to have a True Value otherwise a false it looks like this I'll have it compose I'll go into the expression and here I will have a start with then I'll have a parenthesis now I'll have my variables and our text first part and then I can specify what do I want to search for here I just want to say Mr Mister or Ctrl a control C again it looks like this and this will give us a true false value and since this one this text is indeed starting with Mr then this one will give us a true value and let's try to force it to look for something else and here try to look for we can just sorry I put in and just put an X in front of the mister control a control C and as you can see it's often just a better solution just to delete it and add a whole new expression there you go so now let's save and test and this will result in a false Boolean so if I go to the compose you'll see the false let's click edit it's also rename this so we have it if we want to use it at a later point starts with now I want to introduce you to a kind of important function as well a function that we use a lot that is the split a split let me just open up the first variable up here a split will split a string at a certain certain character for example I can say split this string add a comma then it will split here and it will split by the next comma as well so we will have three strings in out of this if we split by the comma this will also give us an output not in a string anymore but an array an array of strings we will have an array of three string elements the first element that will be is then Mr dursley of number four second one that will be a space and pivot drive and the third one will be the last part here then we when we have this array we can work with it but let's take one step at a time so we will go down here take a new step and find a oh here and I will say say compose split Pro what we want to do is to sorry I only need to go into expression what we want to do is to do a split and here I will have the variables again this can seem trivial but it will our text it will train you first hard then I want to have a comma and now I have my separator this separator is a string so again we'll have it in single quotation marks and put in the comma Ctrl a Ctrl C OK OK and here you can see the expression let's try to save it and let's test it and see the that we can get out Ray if I go in here now we have our output and this output looks exactly what we expected it to be it is an array and you can see it's an array but these hard brackets up here and here and the comma separated values so we have the mist and Mr sturgeleaf Number Four as the first string then privet drive as the second one and this we're proud to say exactly like we predicted then we can start working with this array and to work with an array we can do it in two ways we can either for example get a specific element out say I wonder second one or we can iterate through it and here let me just edit let's try to get a specific element out so I'll say compose and I'll do this so split specific element like this and then we can write an expression so to get out the output of this compose split that was the array that we saw before we can just do an output you can use the output a lot and then we will have the name of the action our action in single quotation marks is named compose then an underscore in a split like this this one will give us the entire array since we are only interested in let's say the second one that was the space and the private drive we go in here behind have a hard bracket and then we give the index of the element that we want out of the array since we want the second and an array is also sear index that means we should write one in here so I control a control C okay okay I'll click save I'll test it and we will have it here so that's it we have the private Drive printed out but let's say you often want to have each element in an array and we can also um apply we can also apply sorry we can also iterate through each element of that see so to iterate room we just find and apply to each yeah and what we want to do again we want to apply whatever that is in this array now we will just refer to it because we will need the entire array and apply to each we'll cycle through a collection so I just do this and I'll find the output of the compose split so that one is here then we want to do something we can for example we can just um have another compose that will write these things out we'll have it compose and what I will do here is simply just to take the current item of um of this up here and this one we can write another expression as um just do this items and then we will have the name of the actual free apply to it so we will do this this one will get the current element write it out roll a control C like this and now we will run this apply to each three times and that is because of course we have three elements in the array so we're still running and this one it's ready you can see here we did have three occurrences we have the first one that is missed and Mrs dursley of number four the second one is the private Drive which we already printed out up here and the third one is we're proud to say that they were perfectly normal it's that easy to work with the split and erase let's also see another important one this is um this is the trim and a trim simply just take white spaces in the start and in the end and make them go away for example if we looked at our text second part you can see that we have a white space at the very start we have it here or we have it now at least um so then the trim will remove this white space and it's very very easy to to apply we'll just have another compose here we'll do this it's just also rename it so I'll have a trim here what I will do is to go to the expression I will say trim and then we will have the variables our text second part control a control C and we haven't lost any expression today but you always careful as as power to make developer so now we added a we added a space at our check second part one space and with the compose trim we trimmed it away it's a bit hard to see but you can see it here we can also go to show row outputs and here inside this one here it's much easier to see the next power automate lesson is right here on the screen for you you should go click it
Info
Channel: Anders Jensen
Views: 8,291
Rating: undefined out of 5
Keywords: power automate, string, power automate string, power automate string function, power automate string functions, anders jensen, power automate beginner, power automate tutorial for beginners, power automate split, power automate split array, power automate string manipulation, power automate replace, power automate substring, microsoft365, microsoft power automate
Id: zaWkvpI4oeg
Channel Id: undefined
Length: 32min 15sec (1935 seconds)
Published: Fri Nov 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.