Hi, everyone.
So in this lesson, we are going to learn what is a string class.
So we started about object oriented programming and we know what is the meaning of a class, so stringers
and world class, but we can use a string as if it is a data type.
So what do I mean by that?
So basically what you can do, you can write something like this.
String did a type.
The name is S and let's say ABC.
So here String is behaving as a day to day.
That's why I told you that we can use a string as a leader type symbol, so we'll string actually behaves
like the correct.
But what is the problem with the character?
So the problem is basically we have to always take care of character.
So this character, but this is not the problem with strings, so let's see how we can use the strings.
So let us create a string.
String, as let's say it, is containing ABC and then you can bring to a string.
So let's see.
So ABC is getting printed.
Now, you can also do like this.
So let us create one more string string as to.
And you can ride like this so as to is the E.F..
And now let us bring as to.
So ABC and the.
So basically, you can also create a lasting dynamic.
So here we are creating strings statically, let us know, create string dynamically.
So a string start, string pointer, this is new string.
And now let us give the values star SB.
Let's say it is.
Aminul.
Now, what will remain output vibrant, Espie, so the output will be addressed if you want to print
the content.
You have to use star status S.B.
And then you will get the content, so let's see.
So this is the address and this is the content, so you have to give state of footprinting the content
and if you will not give the defense operator, it will print the address.
So addresses is stored in hexadecimal format.
Now, suppose you want to store multiple strings, so in that case, if you do not know, how will store
multiple strings, so you have to create a truly array of characters.
So get a and then you have to create a truly array of characters under the cross hundred.
And in this one, Red Cross and Red, basically your first instinct will be stored here, 029 Grain,
then your second string, then your third string and so on.
So this is not a good way.
The good ways, what you can do, you can write that rough string.
String is going to behave as a day to day so you can write like this.
So what will happen?
You will get a vector.
And each and every of vector is basically a string.
So each and every effect is going to be testing.
So this thing is much, much powerful than this tutelary, because you are using string and you're also
using vector.
So basically you have power of a string function, all the function of string class, and you have power
of all the function of the vector class.
So let's see, so let us create a duty area so suffocating the judiciary, we will always ride like
this, testing we and for pushing one element, what the hell do you have to push a string?
So let us push the content so we don't push back.
Let's say I want to insert this string as so we don't push back.
You can write this.
Let us insert one more thing.
Let's say we don't.
Pushback.
Hello.
And similarly, you can print the content, so for printing the content, you just have to get rid of
a director.
So I call zero a list and we dot size.
So, Victor, I say function.
And then you can print the content so we have a BFA is actually a string, so let's see.
OK, so we have to include Victor.
So you can see ABC is this one, and then we started hello.
So Victor Offspring is behaving as a truly very.
OK, so what else can we do?
So you are inserting the elements, you can also call the function site.
So when you first you print this element, then let's start.
So how you will sort be of a so what is view of a is a string.
So you will give the Eurofighter begin.
And you will give B of A is a string, so you will give V of a dot and.
And now let us sprint, we offer you again.
Let's see what is there.
So it was not declared in this scope.
OK, so this site function, this will function is declared in algorithm liablity.
So let us include that library also.
Now, later, up around.
So ABC, after citing ABC, it is still ABC because the AlphaBeta sorted according to the lexicographical
minus.
So after sorting.
So what is happening here?
So first hosting was ABC.
So if you will start ABC, then it will become ABC only because it is less than beebees, less dense.
So in this way, the alphabet's are getting started.
Now, if you want to start.
Hello.
So which one is the smallest.
So is the smallest.
So you will come out first, then each, then similarly l.n. and then or so after sorting hello will
become this one.
So basically you can start your tutelary.
What we are doing, we can sort our character to really.
So if you want to sort of get to the area, it will be difficult.
But let's see, it is so much easier if you are using the crusting for creating a truly array of characters.
Now, let's do some more functions of string so we can take input, so we're taking input, let us create
one more string s three, so string three and we can take input.
So seen as three and let us also print as three.
So it is waiting for my input, let's say the input escorting and the output is calling.
Let's put out one more time.
So, again, it is waiting for my input.
Let's say the input is due space according.
But this time it is taking only do so, we have seen this problem before.
Also, what is the problem?
So the problem is due to in seeing is creating all the problems, because scene will stop taking your
input as soon as it will encounter space.
Or Tab's.
I basically newline character.
So this is saying is the problem in this case now, if you remember, what is the solution?
So the solution is using the function, seeing not getline.
Now, this function seemed odd, getlin function takes three parameters as input string name, the second
one is size and the third parameter is actually optional, which is Delimiter if you remember.
Now, in this case, so this was the situation when we were using correct theory, but here what we
are using, we are using strings.
So what I will write a scene or gridline.
S.
S is basically my string now, the third barometer's option, but what about the second parameter?
What about size?
So this is the property of a stingless.
That you do not know the size.
Basically, you can give anything as input.
You do not have to worry about it.
So basically I cannot use seemed guideline function.
So let me show you.
So instead of saying something is wrong, if I will use Signor Getline function.
S3 now the second parameter is actually size, but we do not know the size, it is the property of the
string class that is the advantage of the stingless.
Basically, you can give anything as input.
You do not have to worry about size.
You do not have to worry about character.
So that means I cannot use Syndergaard name function.
So for stingless we have the function.
We will write it like this getline.
They can put something and put the input in S3.
So this is the way for taking input, for taking input of space.
Kind spaces will be there.
So I have to write like this getline take input from scene and put the input in S3.
So Lozzi.
Now, this time, if you will give and would like do space cording, so our output is correct.
OK, so this is working now, so you have to use Getline and you can remember this.
And it is very simple.
Syntex.
So you do not have to worry about the length of this thing, you do not have to worry about the little
character.
So everything is working perfectly fine.
Now you can treat string's as if it is an eddy.
So what do I mean by that?
So after taking the input, let's say I want to change my string so I can write like this as trees.
Let's say it is.
ABC, ABC, later, this is my news.
So what do I mean by that so you can access it like this?
What is the first character?
What is the character presented?
The first index.
So it will be B, so let's see.
OK, so it is waiting for my input.
So do quoting now, the first character is actually being widescreen because after taking the input
from the user, you are changing the value of S3.
It is ABC, ABC and the first character is actually B, so you can read your strings.
Like if it is an integer like it, like it is an eddy.
So it will ask me for the input again and again, so let us come into out.
Let us also point out this line.
OK, so if we can access that, obviously, I mean, you can change the value also, so let us change
the value.
So let us change the 08 character, the character person to zero.
Next, let's say I want to make a deal so we can definitely do it.
We can do testing as if it is energy.
And now let us sprint as three.
So the zeroth character has been changed.
It was initially, now it is so DBC and ABC, you can see so this is BBC and ABC.
So my character is now the.
So what else can we do so we can add two things?
So what is the meaning of two strings?
What is the meaning of adding two things?
So let us create one most things together and you can write it like this.
String three.
Plus, so this is stingless, so let's add these two stings, so sting three plus string, as do we
have another string, OK?
So let's take it as to silly string.
So as for this history lessons to know what will happen.
So these two things will get added and the output will be stored in a sting.
Asfour So let us write it like this.
So as for.
And let us also bring to to industry.
So as to.
As three.
So let's cut it from here.
And let's be heard here.
OK, so I'm using this plus operator to add a string S3 and string as to.
So this is your string as to which is the ITF and this is your string.
So this is ABC, ABC.
So let's see what will be our output.
OK, so let's come and get out.
Let's remove Sting, let's put this call about.
The.
So you are printing as you got printing a story and you are printing Asfour, so what is as true as
is you can see the ECF so as to his beef, what is a three?
So it is ABC, ABC and you are changing this character to the still string three is actually BBC and
ABC.
And then what they are doing so is three plus S2, so this plus operating what it will do, so three
plus S2.
So this plus operator will work as concatenation, so it will concatenate string S2 at the back of String
S3.
So this def will come at backoff string S3.
But what this plus operator will do, so it will add, it will find out the result and it will return
the result.
So the result is going to be stored in S4, so S3 and S2, so there will be no change for it.
So you can see.
So your decision as to which is def correct.
This is your stream is BBK, ABC, so this is DVC and ABC.
So it is correct and this is your string S4.
So testing as well is actually BBC, ABC and then beef will get appended D.F. So this plus operator
can concatenate two strings and there will be no effect on Estragon S2.
So this plus operator will find out the result and it will return the result.
And that result we are storing in a string S4.
Correct.
So that is the power of string.
We can simply with the help of this plus operator, we can just add two strings.
So we can add boosting, we can also add multiple strings, so, for example, you can write to tell.
You can read it like this also, let's see.
So this is your output.
This is your stringers for the ABC, the F Hello Space Cording.
So that is the power of stingless.
Now, you can also write it like this where you can do.
So what you can do?
Initially, us springford.
Usually the swing vote is actually empty.
It is, it is, and it is not containing anything, then you can write it like this is four plus equals
two.
So I can also use this operator plus equals to.
So let's see.
So this is your output.
So you can use plastic cultural operator also.
Now, what is happening in this situation?
What you are doing, you are using plastic to operate.
So what is the meaning of this line?
So as for equals as four plus three plus as two plus, and then you have this very long string hello's,
rescoring.
Now, what is happening so this Hallowes bickering will get upended after and still not a combined result
of his two plus helicopter will get upended at street behind the back off at the back end of history.
And no combined result of three plus as tubeless helicopter will get upended after S4, what is actually
pretty strong.
So this is interesting.
So we also have a function size.
Let us try to print the size.
So let's try to bring this so out, you can call sales function, let's say I want to call the sales
on Asfour.
So as for that, sales.
Or you also have the function as darkland, so as for Nordlund, so Nordlund and Darcis, both the functions
are the same.
They will give you the same output so you can use any function, you can use function or you can use
lenth function.
They are they both are same.
So you can see 21 and 21, so this is 21 different characters, so these are two different characters.
OK, so what other functions do we have?
We have one more function, and the name of that function is substring.
So what they can do as for dot substring.
So this subsetting function will take the index, so let's say I'm giving index three.
So what does substring function will do?
So suppose this is costing.
ABC, ABC, and if you call the function Astarte substate, so Sebastiani means substring and it will
give the index.
So I want to give the index three.
So what will happen?
This is the index zero.
This is index one.
This is indexed to and this is index three.
So starting from industry till the end, it will give me everything.
So it will give me ABC.
This will be the output.
Now, if this is your string later, this is ABCDE.
And if you call the function as a substitute and if you will give index zero.
So starting from index is zero.
The end, it will give you the output, so the output will be ABCDE starting from the index zero in
the last index, it will give you all the characters.
So that is the meaning of substring.
OK, so let's check our substring function.
So I'm calling substring function on S4, so starting from Index three till the last index, it will
give me all the characters.
So let's see what that output.
So the size is 21 now, what is it next to you, so the auto industry starts from E!
So starting from E till the last, it is giving me everything you can see.
It is a starting from ABC, ABCDE and then recording this.
So starting from industry, I have given industry here.
So starting from industry till the last and next it will give me all the characters.
So it is giving me all the characters.
Now, there is one more variation of substring function.
So what is the second variation, so in the second variation, what we will do so in this, I am giving
only one value as input.
Now, in the second variation, you will call the function Sebesta, you will give the starting index
and you will give me how many characters do I need.
So here what I'm doing, start from industry and give me three characters.
So basically it will give you the character presented index three.
It will give you the character personality index four, it will give you the character presented Index
five because the length has to be three.
Now, for example, if you will call the function as dark Sebesta.
So start giving me characters starting from zero and give me two characters, so the output of this
line will be Ebbie because this is zero character.
This is one character.
And so it will give you the character presented zero index.
The character plays in that one index because I have to give only two characters because the length
is too.
So it will be my output.
Now, one more thing.
So this substring function, it will not change my string.
It will just return me the substring.
So basically you can do something like this as two is as Sebesta.
Zero Komada.
So this substring function, it does not change the original listing, in fact, it returns the new
string.
So let's see.
So starting from so starting from the third character, starting from the third index, give me five
characters.
So let's see what we output.
So this was.
So this is the five characters starting from industry, so ABC, the OK, so starting from industry,
give me the five characters so it will give me the character presented the next three, four, five,
six and seven.
Simple and what you can also do so you can store the resulting in the string and you can be interesting.
So let us store the desert and S5.
And you can print as five.
So basically, this substring function, it will not change the original listing symbol.
So let's test.
OK, so this is Annalyn.
So absolutely perfect.
OK, so what other functions do we have so we have one more function find function.
So basically what you can do, you will call the function find.
So as for DOT.
Find and I want to find various ABC president.
I want to find a way it is ABC president and Stringer as food.
So how a find function works, so suppose this is your string.
Let's say this is the if ABC, ABC and then again ABC, and if I call the function as not find.
ABC.
So basically, I want to find various ABC present and this is string, so ABC is present here.
ABC is present here.
So this fine function will return an integer.
So this integer is actually the index.
So an index of various this ABC present.
So this ABC is presented multiple locations.
So zero one two.
So this is indexed three.
So ABC is present at index three.
So this is four, five, six, seven, eight.
And then this is nine, 10 and 11.
So this ABC string is presented through index.
It is present at index three.
It is pleasant out index six and it is pleasant at Index nine.
So three times this string ABC is present, this fine function will have done me the first index, the
index at which it will find the ABC first.
So the output will be three.
Now, if the string is let's say this is ABC, then ABC, then AC and then ABC.
So if this is the string and I call the function as Dart Find.
String ABC, so what will be my output?
So where does ABC so is present here only so.
The index zero one, two, three, four, five and six, so it will return me six.
Correct, and if there are multiple locations at which the string is present, it will give me.
The index of the first location.
So I'm calling the find function.
I want to find out which is ABC present interesting as food, so it will return me an integer.
So ABC is presenting the next three, so let's see.
So this is the string S4, you can see ABC.
So ABC is present at the next three, so that's why the output is indexed.
Three.
Perfect.
So what other functions do we have?
We have a function to string, so, for example, you have an integer, let's say it is 123.
Now you want to convert this integer into a string.
So what you can do.
So let us create a new string.
String a six.
So we have a function to underscore string.
And we will give you guys input, so it will return me the string, it will convert integer into string
and let us sprint as six.
So this six, this is six, so 123 is now string 123, so I'm repeating myself, so this is 123 integer,
this is 123 integer.
Now you are playing function.
Boosting and boosting function will take integers input.
So this boosting function, it will take integers input.
I am giving 123 and it will convert the integer.
Interesting.
So this is now string 123.
Fine, so desisting one, two, three, you can change the values also because we can we can we can
treat the strings as if it is NATO.
So let us change the characters.
So, for example, I want to change.
The first index, the of the first index, let's say it is for now, because it is a string, so you
have to give credit for not integer for.
So this is characterful now and now, let us also bring Essex again.
So 123 was my original listing.
Now I change to in dofor, so the is now converted into four.
So we have a function to similarly we also have a function you do okay, so so I'm using it again.
So this is a.
So this is actually we have a function, you do okay, now this is the wavefunction, it will take a
string as input and it will return within a year.
So now let us spend a.
OK, so I don't know in which library to wavefunction this present.
So what I'm going to do.
So instead of these three.
OK, this is wavefunction is not working.
OK, so for walking of this IT wavefunction, I think you have to write something like this, a six.
Nazi and let's go to St..
OK, so now it is working.
So this is wavefunction, what it does is it converts the given strength into an integer so that it
wavefunction it will take integers.
And so I am giving it will take a string as input.
So I'm giving a six, so I'm giving one four.
So I'm giving 143 and it will return me integer 143.
OK.
Now, let's say if you want to insert elements.
So you want to insert element in ethics in a string so you can use push back function just like in vector,
so I want to push back, let's say I want to push back five.
So five will get pushed.
So let's run our program again.
So one, four, three, five.
OK, so let us also print Essex, then we will print a.
So after pushing five letters, now opened a six.
So what is happening here?
So this was your 123 then to function will convert 123 integer to 123.
Strength, then you are changing the first character to force, so this will become 140, then you are
pushing five, so this will become one, four, three and five.
You are printing a six.
So one four, three, five is getting printed here.
Then you are using it to wavefunction.
So it wavefunction will convert it into integer.
So this is one, four, three, five and then you are printing.
So it is getting printed one four three five.
So that is how everything is working.
So we have also pushed back function just like in vector.
So you can see strings are much, much powerful then the character.
Now how the strings are working.
So string.
I told you so.
String is actually a class so string is actually a class.
And in the implementation of this class, basically it is using connectivity.
If you will see the implementation of the string class internally, it is using area only.
So I think I have covered many functions of a string.
So if you have any doubt in any of these functions, you can ask me, I will share the call with you,
so I will see you in the next one.
Bye bye.