In this video.
Let's talk about another property and methods that we can use to operate on strings.
So in this video, we will talk about three of the methods because they are simple to use.
And after that we're going to have our another coding challenge or have a coding challenge.
So let's comment out.
This one's the one we solved here.
This one.
So.
Okay.
I can leave it because I'm not console.log anything here.
So here the methods that we are going to talk about right now is what let me have.
The first one is called trim.
And then next I'm going to be to.
Uppercase and then to.
Lowercase and then lowercase and then talk about index of.
So let's start with the trim.
So the trim is used to remove wide spacing around a particular string that is from side by side.
So like I explained to you before that we're not trying to find a length of a certain character.
It takes the white spacing into consideration.
So white spacing simply means that spacing around a particular text.
So let me show you what I'm in here.
Let's declare a variable cost.
And let's say this My string is equal to quoting time.
Like that.
So for this one, there is no wide spacing because there is no space around the text here.
Okay.
So as soon as I bring some spacing here, this vertical wide spacing, if I save it, it's still there.
Right.
So to remove that, make sure you have some consistency in your data, in your application.
You need to trim that particular test.
You need to what?
Sanitize it, scrutinize it to make it the way you want.
So because of that, you're going to use a method called trim.
So let me declare a variable core result is equal to my string and then trim.
I have that as a method.
Great.
So now let me console.log this one console that log the SD or the original one like that and then dart
length.
That the first one.
And then after I trim it, I want to find the results.
The console log, the results dot lamp.
I don't know whether indeed it has been trimmed.
For the meantime, let's remove the method here.
Let me show you something here.
If I save it, you can see that.
Have a look at differences here.
If we see that for the first one that has peace in Syria as I'm facing here, but we cannot see how
they can as well as push to the side.
But after I trim it because I remove the white space and that's why I have it be on this side or look
at this one.
There's some space here.
And as that, let me prove to you, well, this one is supposed to be here and then supposed to what?
And here.
But because this one has some white space and just push, it has a space and then push it to the side.
So that is that is how the dream weighs.
It's really I mean, nice method we need to understand.
So again, if I want to find the length of this particular before Trymaine and then after Trymaine,
let's see after Trymaine, we see that the first one, because I have some space in it, has given me
16 characters, which is which is weird.
And then this one after Trymaine, I got 16 characters, meaning I have trimmed five off.
That's about a trim.
The next one is so let me remove this one from here.
I can comment out.
Yeah, okay.
Yeah, yeah.
Let me comment out the next one.
Let's talk about the two uppercase and to lowercase.
As the name implies, it is to convert.
A string from lowercase to uppercase and uppercase to lowercase and vice versa.
So this one going to be to lowercase and to uppercase.
So let's have the same text as code in time.
So it comes code in times I'm around.
Let me make it nice.
I want to trim it.
So let's say for the uppercase.
So let me console.log quickly here, because it is a simple method.
There's no time to waste on this one.
And let's start with our coding challenge.
So on a string I have a method called to lowercase.
To.
Lowercase and then if I save it, we see that it has converted everything to lowercase even though it
is uppercase.
So let me make everything uppercase here as codeine and then type.
You see that test converted everything to lowercase.
So four lowercase h two lowercase.
So for uppercase the same as to.
To uppercase.
So if I change this one to everything, I mean lowercase, let's say coding.
Accordion time if I save it, see that it has converted everything to uppercase.
The last method we are going to use, then we start our coding challenge is what we call the index of.
Because we need this logic before we can solve the we can solve the challenge of the coding.
That's why I am explaining to you before we start with that.
So index of well the index of is used to determine at which particular point a certain character appears
or is.
So let's say that.
Let me bring back this string here.
Call.
Costs as are coding time.
If I want to know at which index once the index simply means at which place that a particular character
exists.
We have a specific video to dive more about a race.
For the meantime, just bear with me.
So I rest I index base zero base meaning that is start from zero when you count 0123456, seven, eight,
nine, ten.
So let's find out what index that see okay so on the start my string dot index of now to find at which
index does this C or K, so I'll pass in C.
Like that.
So let me console.log the results.
So const.
Results is equal to that.
Is equal to that.
Yes.
So if I console.log the results.
Let's see it.
Okay.
At index zero.
That is it.
So 4d404040.
Here it occurred at index one.
That's why we have it here.
Remember?
Index of r k sensitive.
Meaning that this one is.
Uppercase A lowercase C and you pass in uppercase C.
We're going to have some strange results.
You see that negative one.
So if a value doesn't exist, it returns.
What negative one?
And we can make use of in this off to make a little of logic meaning if you're are trying to find if
a certain letter appears in a maybe some characters or where appears in certain string to ten minus
one, which doesn't exist, for example, we can have a list of uses and we want to search for a certain
user if you pass in and that user doesn't exist, the index of is going to return negative one.
So let's say that I want to find four time.
Here if I save it.
Yes, it's worked at index seven.
Meaning it exists.
That's why we have it here.
So the key note here is that the index of always gives you a negative one if it doesn't exist and it
gave it a number at where it occurred, if it exists.
So on that note, let's have our first challenge under trim and index off in the next video.