In this video, I'm going to show you how you can use the library, stringer, and how it can make your
work with strings easier.
As the name of the package says, make it easier to work with strings.
So that's quite telling, I'd say.
Basically, if we take a look at the Help page for this package, then you can see that there are quite
a lot of functions which are specializing solely on how you can work with those strings.
And basically most of those functions begin with the letters SDR and then underline.
And then there is something like extract, locate length and stuff like that.
So that is generally the syntax within this stringer package.
I'm going to show you some of those functions for that.
I'm again specifying test string and number string.
So those are our two strings which we are using for those examples.
The first thing I want to show you is how you can add two strings together.
So how you can add this test string from over here and this number string from over here.
I'm using STR underline C, so that's string concatenate and then I'm concatenating number string and
test string.
And I do not want to have a separator between those two strings.
So therefore I'm specifying separator equals empty quotation signs.
So I'm going to run this line and now we can see that we have those four elements concatenated or fused
together into one string by using the string package and the string concatenate function.
Then there is, for example, the string or STR underline count function, which actually enables you
to count the occurrences of a specific symbol.
So I'm going to run this line on the number string.
I want to search for the number of occurrences of the number three.
So I'm going to run this line.
And as you can see in the first element, we have two times this, number three.
And then the second element, it is one time.
And that is exactly what is happening in this number string, because as you can see, we have a three
over here and a three over here.
So that's two times in the first element and one time in the second element.
So there was the string count function.
The next one we can take a look at is the string locate all function.
This one actually allows us to locate the first and the last position of a symbol in a given string.
So in this case, I want to identify the position of the symbol or the number three.
So I'm going to run this one.
And now you can actually see that in the first element we have the number or the symbol three at the
first position and at the 23rd position.
And in the second element, we have it at the 31st position.
So that's actually how you can locate specific symbols within a string, which I think is also quite
a useful tool in the string package.
And the last functions from the string package I actually want to present to you are string, underline
replace and string underline replace all.
And those are the exact equivalence to the sub and g sub functions from the base package.
So let's take a look at the equivalent to the sub function.
So it's str underline replace and then I'm choosing digits to replace the first digit in each element.
So as you can see now, this number over here has gone and there is also a number missing from over
here because this one was actually 11in the original number string string.
And over here there is a three missing.
So this one is also been deleted as the first number in this element.
And if we actually want to remove all those numbers, so all those digits, we can use the string,
replace all command and now you can actually see that all those numbers have gone.
So that's quite similar to the G sub function from the base package.
At this point.
They also want to note that there is the library cheese up fun, which actually can be quite useful
to incorporate functions into a typical cheese sub line.
If you want to replace specific letters or specific words with whole functions, you can definitely
take a look at this package.
All right, guys.
So that was actually how you can use the stringer package to do some string manipulations in our.