‫All right.
‫So in the last video we looked at functions that will help us with math and numbers.
‫Now we're going to look at functions that can help us with strings.
‫So I have just the the HTML template here.
‫And I'm outputting just output.
‫And I have output set to null at the top.
‫And I'm doing it this way just so I don't have to do a bunch of different echoes.
‫We can just fill that variable.
‫So let's put a string into a variable as well, so we don't have to keep typing that out.
‫So we'll just do Hello World.
‫Put it in a variable called string.
‫So the first function that I want to look at is string length which is str Len which you can probably
‫guess what that does.
‫It gets the length of a string.
‫So we'll say output equals and then str Len.
‫And it takes in the string.
‫So if I save that reload we get 11.
‫So it's going to count the characters here including the space.
‫And it gives us 11.
‫Next one is going to be str underscore word count which is also pretty explanatory.
‫It'll give us the word count.
‫So if I say output equals str underscore word count pass in string.
‫And we reload.
‫Obviously we get two because there's two words here hello world.
‫Then we get str pos which is the string position.
‫So what this means is if we want to get a substring like let's say the word world, it will give us
‫the position of where that starts and the position is going to be based on the index.
‫So just like arrays and I know we haven't talked about arrays yet, but each array item has an index
‫starting at zero with the string.
‫We also have indexes starting at zero.
‫So this is 0H123456.
‫So if we look for the position of world it should start at six.
‫So let's say output.
‫And let's set that to str pos.
‫And that's actually going to take in two arguments.
‫It's going to take in the string that we want to search for the substring.
‫And then the substring we want which let's say the word world.
‫So if I reload we're going to get six just like I said because it's going to start at 0123456.
‫And you can get the specific.
‫Let's just do this.
‫Let's say get specific character by index.
‫So I'll set output.
‫And let's say we want to get string.
‫And then we can use brackets here to get whichever index or what value from the index we want.
‫So 01234 let's do four which should be the O.
‫So if I pass in here a four.
‫And then we reload.
‫You'll see that it gives us.
‫Oh, so you can get any character within a string using its index.
‫So the next one is going to be substring, which is kind of the opposite of string position.
‫Because instead of passing in the the substring and getting the position, we're passing in the position
‫to get the substring.
‫So let's say output and we'll set that to it's it's substr.
‫And that's going to take in three things.
‫It's going to take in the string, and then it's going to take in where we want to start.
‫So I'm going to say at the sixth position which is the W where world starts.
‫And then the length where do we want to go from there.
‫Let's say the next five characters.
‫So it's going to start at six, which is right here.
‫And then it's going to get one, two, three, four, five.
‫So it should give us the word world.
‫Okay.
‫And there's plenty of times where you're going to have to pluck certain words or certain characters
‫out of a string.
‫So the next one is string replace or str underscore replace.
‫So let's say output.
‫And you can probably guess what this does.
‫We can replace a sub string with something else.
‫So it takes in three three arguments.
‫First is going to be the sub string we want to look for let's say world.
‫Second is what we want to replace it with let's say universe.
‫And the third is the is the string itself.
‫Okay.
‫So if I save that what we should get is hello universe because we're saying look at this string, find
‫this sub string and replace it with this sub string.
‫Okay.
‫Next we have some pretty simple ones, but pretty common string to lower, which will make it all lowercase.
‫So output equals string to lower.
‫Pass in our string.
‫And we should get Hello World, but in all lowercase.
‫And then we also have string to upper, str to upper.
‫And we'll change that.
‫To upper.
‫Okay, now it's all uppercase.
‫If you just want the first letter of each word uppercase, you can use U.S. words.
‫So let's say output equals U.S. words.
‫String, and then just the H and the W should be uppercase.
‫And then the last one I want to show you is trim.
‫So if I say output and I'm going to set this to a string where I put a bunch of spaces before and after,
‫and I'll just go like that.
‫Now in the browser it's actually going to be.
‫Formatted just fine, like we don't see any spaces before it.
‫But if we view the source code.
‫You can see there are actually spaces in the HTML.
‫So to clear that up we can wrap this in trim.
‫Like that.
‫Reload.
‫And now that gets rid of the spaces.
‫Okay, so that's it.
‫Now, if you want to look at some other string functions, you could check this link here from the documentation.
‫But these are the most common ones that you're going to be using.