All right.
Next up, there's a few other string methods or string functions that I think are worth knowing, but
I'm going to hit them quickly and not make you watch a separate video for each one.
The first one is called Inserts.
It allows us to insert some substring into a larger string.
It doesn't actually have to be a larger string, but some string into another string at the beginning,
in the middle at the end.
So it's different than replace because replace is going to replace some existing characters with insert.
We can replace characters or we can simply add on.
So let's say that I had this string not replace insert.
How about Hello Bobby like that?
And I want to insert something right there where the space is.
How about there?
So it's Hello there, Bobby.
Very contrived example.
Of course we would just type that string.
But imagine I'm doing this on every single row in a table for some column.
So.
Hello, Space.
Bobby.
I'm going to say I want to insert something at this position, so I have to count.
One, two, three, four, five, six.
So it depends on how I want to do this.
If I do six, let me just show you what happens.
There's a second number I have to provide, which is the number of characters I want to replace.
And in my example here, I don't want to replace any characters I'm adding on, but I'll show you what
happens if we change that.
And then what am I adding on there?
The string there.
So this is what we get.
Hello.
And then there, that whole string was inserted right at this position and then the space is still preserved
and then we have Bobby.
But I could have rewritten it so it had a space at the beginning.
So we get Hello there, Bobby.
But let me show you what happens now if we instead say replace some characters.
So instead of just saying replace nothing and insert there at index or position six.
What if I say replace?
I don't know four characters?
This is what we get it replaced for characters, so it inserted there.
But as it did that, it replaced the Bobby.
Or if I did it, I don't know, let's replace six characters now we just have Hello there.
We replaced all of Bobby.
So that's insert.
If you're just trying to replace something like for like replace all examples of something within a
string, then you can do that using replace.
If you want to insert something in the middle at the beginning, at the end you can use insert.
It is a little confusing with those two numbers.
Just remember this is where something will be inserted.
The second number is how many characters to replace OC.
The next function I want to talk about is left.
Left and right are functions we can use to get the leftmost and right most characters from some string.
So in this case we're getting the leftmost five left most characters from foo bar bar, which is FUBAR.
One, two, 345.
I'll just show that really quickly.
Select left of the string.
OMG haha lol exclamation point I say how many left?
Let's get the three left.
Most characters add my semicolon and we get OMG and if I instead did right and get the three rightmost
characters, well it's going to be all exclamation point.
So let's maybe get the four rightmost characters and we get lol exclamation point.
So we could have used this for example, to get the initials or create the initials of our authors.
Let me just get let's say we want the last name, the first character of the last name, what we could
do Select left of Author L Name one character from the left, meaning the first character from books.
And we get L right.
That's Lahiri.
G is for Gaiman and so on.
So that's left and right.
We also have repeat, repeat does what it sounds like.
You take some string and a number and you'll get that same string repeated that number of times.
So if I have a string, select, repeat, huh?
Four times we get.
Ha ha ha ha.
So I think that's all I need to show.
You could use that, of course, with a real table.
That's why you would use this.
You probably don't need to repeat half four times, but for the sake of your own time, I'm not going
to show an example of that.
And the last one I'll show you is trim.
Trim is used to remove usually spaces that are leading and trailing.
So if I have some data that is messy, maybe it has.
Let's just do a trim on some string that has some extra space around somebody's city.
How about Boston and then a space at the end?
I don't want that space there.
If I trim it, it removes the leading.
And trailing spaces, but it's not going to remove the spaces in the middle.
Like if I had San Antonio.
It doesn't remove all spaces.
It's not a replace.
It is simply removing, leading and trailing spaces.
But we can actually trim other characters if you specify a certain character.
So here they call it remove string or rim string.
So something like this right here we can say trim the leading x characters from this string.
It's kind of weird, the syntax, writing, leading and from.
But let's just take a look at an example.
Maybe I have something that looks like this.
For whatever reason, there's a bunch of leading dots periods and trailing dots.
Well, if I do that, it's going to look for spaces on its own.
That's not what I want.
I'm going to say trim leading period characters from that string.
And there we are.
It only trimmed the leading ones.
If I instead had said Select trim, trailing.
It will only remove the trailing dots.
And then I could also say both to remove both leading and trailing periods.
All right.
So that's it for this wrap up of some additional string functions.