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 in the class but we can use a string as if it is only to type.
So what do I mean by the type.
So basically what you can do you can write something like this string due to type.
The name is s and let's say ABC so here.
String is behaving as a data type.
That's why I told you that we can use the string as a data type symbol.
So string actually behaves like the correct binary.
But what is the problem with the correct bearings.
So the problem is basically we have to always take it off null corrector so disconnected.
But this is not the problem with strings.
So let's see how we can use the strings
so let's create a String
String s let's say it is containing ABC and then you can do a string
so let's see
so ABC is getting printed
now.
You can also do like this so it does create one more string string as to and you can write like this
so as to is the E F and now let us print as to
so ABC and the F so basically you can also clear distinct dynamically.
So here we are creating strings statically let us now create string dynamically so String start String
pointed.
This is new string
and now let us give the values so start SB let's say it is and then no.
Now what will be my output the fine print SB So the output will be addressed if you want to print the
content you have to use Start.
Start SB 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 a start for printing the content and if you would not give the defense operator
it will bring to the ad bus.
So this is stored in hexadecimal format.
Now suppose you want to store multiple strings.
So in that case if you do not know string how we list or multiple strings so you have to create a 2D
array of characters.
So get a and then you have to create that to the area of characters under the cross hundred and in this
hundred across hundred.
Basically your first instinct will be stored here.
Zero to 99.
Then your second string then your third string and so on.
So this is not a good V.
The good ways what you can do you can write that rough string string is going to behave as a data type
so you can write like this.
So what will happen.
You will get the vector and each and every of vector is basically a string so each every effect is going
to be a string so this thing is much much powerful than this.
Rudy Eddie because you are using string and you're also using vector.
So basically you have palette 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 for creating the 380 we will always write like this vector string v.
And for pushing one element what we have to 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 s let does insert one more string.
Let's say you dot back
Hello and similarly you can print the content.
So avoid printing the content.
You just have to iterate over the vector.
So I equals zero I list and we dot size so vector has a function and then you can print the content.
So vilify BFI is actually a string so let's see okay.
So we have to include vector
so you can see ABC as this one s and then we inserted Hello.
So vector of string is behaving as if to the Eddie
okay.
So what else can we do so you're inserting the elements.
You can also call the function sort.
So when you first you print this element then let us start.
So how you will sort V of I.
So what is vilify is a string.
So you will give the unified out begin and you will give vilify is a string so you will give.
We'll find out and and now let us bring to vilify you again.
Let's see what is data so it was not declared in this globe.
Okay so this sort function this and world start function is declared in a library so let us include
that library until
now led to an output well
so ABC after starting ABC it is still ABC because the alphabet s sorted according to the Lexx a graphical
minus.
So HLA low after sorting.
So what is happening here.
So first you string was ABC.
So if you will start ABC then it will become ABC only because A's less than B B's latency.
So in this way the alphabets are getting sorted.
Now if you want to sort Hello.
So which one is the smallest.
So even the smallest so even come at first then etch.
Then similarly n n and then.
So after sorting hello will become this one.
So basically you can start your judiciary what we are doing.
We can sort out what connected to the array.
So if you want to sort of connected all the array it will be difficult but let's see it is so much easy.
If you're using that trusting for creating a doody area of characters
now let's do some more functions of string so we can take input.
So far digging in let us create when most things String s three.
So string as tree and we can take input.
So seen as tree and let us well so print as tree
so it is waiting for my input.
Let's say the input is calling and the output is calling Let's now put out one more time so again it
is waiting for my input.
Let's say the input is do space according but this time it is taking on you do.
So we have seen this problem before.
So what is the problem.
So the problem is due to see in seeing is creating all the problems because scene will stop taking good
input.
As soon as it will encounter space or tabs all basically new land connected.
So this is seen as the problem in this case.
Now if you remember what is the solution.
So the solution is using the function C in dark get lean.
Now this function is seen or good main function takes three bottom which is as input String name.
The second one is size and the detector the better midday is actually optional which is dealing with
the if you remember now in this case.
So this was the situation when we were using connectivity but here what we are using we are using strings.
So what I will write a C not good line is as is basically my string.
Now the third parameters option.
But what number the second parameter What about size.
So this is the property of a string class that you do not know the size.
Basically you can give anything as input.
You do not have to worry about sites.
So basically I cannot use seem not good line function.
So let me show you
so instead of scene so something is wrong.
If I will use scene or good line function S3.
Now this second parameter is actually size but we do not know the size that is the property of the string
class.
That is the advantage of the string class.
Basically you can give anything as input.
You do not have to worry about what size.
You do not have to worry about no character.
So that means I cannot use seemed or get named function.
So fostering class we have the function we will write it like this get line take input from scene and
put the input in s.t..
So this is the V for taking input for taking input of space kind basically spaces will be there.
So I have to write like this.
Get Lane take input from scene and put the input in history.
So let's see now this time if you will give input like do space according.
So our output is correct.
Okay.
So this is working now.
So we have to use get.
And you can remember this and fix it is very simple syntax
so we do not have to worry about the length of the string you do not have to worry about it connected.
So everything is working perfectly fine.
Now you can do it strings as if it is an eddy.
So what do I mean Barrie.
So after taking the input let us say I am I want to change my string so I can write like this as trees.
Let's say it is
ABC ABC.
Let's say this is my new string.
So what do I mean by.
So you can access it like this.
What is the first character.
What is the character represented the first 16.
So it will be be selectee
OK so it is waiting for my input.
So do coding.
Now the first correct is actually be why it is being because after taking the input from the user you
are changing the way live S3 it is ABC ABC and the first connect is actually B.
So you can treat your strings like if it is an integer area and like it like it isn't any so it will
ask me for the input again and again.
So let this come into doubt manner.
This one's going down this line.
OK.
So if you can access that obviously mean you can change the value also.
So there does change the value.
So let us change the 0 8 character.
The correct purpose in the data index.
Let's say I want to make a deal so we can definitely do it.
We can do testing as if it does entity and now let's print as three
so the zero character has been changed.
It was initially.
Now it is.
So BBC and ABC you can see.
So this is BBC and ABC.
So my zealot character is now the.
So what else can we do.
So we can add two strings.
So what is the meaning of two strings.
What is the meaning of adding two strings.
So let us create when most interesting guess what.
And you can write it like this string three plus.
So this is String s so let's add these two strings so distinctly plus string as do we have another string.
OK so let's take it as two.
So string so S4 is is three places too.
Now what will happen.
So these two things will get added and the output will be stored in a string as food.
So let us write it like this C out as for and let us also print as 20 30 so as to
as 3
so let's cut it from here.
And let's be started
okay.
So I'm using this plus operator to add a string as tree and string as two.
So this is your string s2 which is the F and this is your string as T.
So this is ABC ABC.
So let's see what we had output
okay.
So let's come on get out.
Let's remove string.
Let's put this cord about
so you are printing as to get printing as three and you are printing as fold.
So what is as true as true is you can see the e f so S2 is the f what is s 3.
So it is ABC ABC and you are changing these character to these two string as three is actually D B.C.
and ABC and then what they are doing so as three plus S2.
So this plus operator what it will do so as three plus as two.
So this plus operator will look as concatenation.
So it will concatenate a string s2 at the back of string S3.
So this D F will come at the back off string as t but but this plus operator will lose so it will add
it will find out the desert and it will get done that isn't so that is it is going to be stored in as
food so as true and as true.
So there will be no change for the.
TIM LESTER You can see so you're this is you are as to which is the F correct.
This is u s team which is a BBC ABC.
So this is BBC and ABC.
So it is correct and this is why this string is full.
So the string s what it is actually BBC ABC and then B if they get appended the E F so this plus operator
can concatenate two strings and there will be no effect on S3 on S2.
So this plus operator will find out the desert and it will get done that result and that result we are
storing in a string as food correct.
So that is the pilot of string class began simply with the help of this plus operator.
We can just add two strings
so we can add two strings.
We can also add a multiple strings.
So for example you can write or tell
you can write it like this also so let's see
so this is your output.
This is your string as for ABC.
ABC the F Hello space calling so that is the power of string plus.
Now you can also write it like this where you can do
so what you can do initially you string for initially listing phone is actually empty it is.
It is an empty string it is not containing anything then you can write it like this as food plus equals
two.
So I can also use this object and plus it goes to so let's see
so this is your output so see you can use plus equal to operator also.
Now what is happening in this situation what you are doing you are using plus it goes to operator.
So what is the meaning of this line.
So as what equals as food plus as T plus as two plus.
And then you have this very long string Hello space calling now what is happening in so this hello space
coding will get appended after as to another combined desert of to place according will get appended
at S3 behind the back of at the back end of history and not combine Düsseldorf s three plus has Duplass
Hello coding will get appended after s fold and s what is actually empty string so this is empty string
so we also have a function size let does try to print the size
so let us try to print these days so c out you can call size function lets say I want to call this a
functional as food so as for dot size
are you also have the function as dark lint so as food Nordland so dark land and dark sides both the
functions I assume they will give you the same output so you can use any function you can use sites
function or you can use lend function that they both have same
so you can see 21 and 21.
So this is drawing different characters.
So these are 21 characters
okay so what other functions do we have.
We have one more function and the name of that function is substring so we're digging to do as food
dot sub string so this substring function will take the index.
So let's say I'm giving index 3.
So what this substring function will do so suppose this is your string ABC ABC.
And if you call the function as DART sub SDR so say Bestia means substring and it will give the index.
So I want to give the index three.
So what will happen this is the index 0.
This is index 1.
This is a mixed two and this is index three.
So starting from index three 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 let's say this is ABC and if you call the function as DART said Bestia and
if you will give index 0.
So starting from index 0 till the end it will give you the output so the output will be ABC starting
from the index 0 in the last index it will give you all the characters.
So that is the meaning of substring Okay so let's check our substring function so I'm calling the substring
function on S4 so starting from index 3 there is a last index it will give me all the characters so
let's see where do you get output
so the size is 21 now what is indexed to you so the index 3 starts from E so starting from a till the
last it is giving me everything you can see it is starting from ABC ABC the F and then held accordingly
so starting from index 3 I have given index 3 here.
So starting from index 3 to the last index or don't 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 version what do we do.
So in this I am giving only one value as input.
Now in the second variation you will call the function sub estimate you will give the starting index
and you will give me how many characters do I need.
So here what I am doing.
Started from index 3 and give me three characters.
So basically it will give you the character presented index three it will give you the character present
at index 4 it will give you the character as in the next five because the land has to be three not for
example if you will call the function as dark so best so start giving me characters starting from index
0 and give me two characters so the output of this line will be b because this is 0 corrected.
This is one character and so it will give you the character present at 0 index no character plays in
that one index because I have to give only two characters because the Lent is too so Eby 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 Dot Sebastian zero comma do.
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 where do you get output
so this was.
So this is the five characters starting from index three so e b c the NDE.
Okay so starting from index three.
Give me the five characters.
So it will give me that correctly present danger index three four five six and seven simple.
And what you can also do so you can store that is thing and the string and you can bring the dead string.
So let us store that the dessert in as Fife and you can print as 5.
So basically this substring function it will not change the original string.
Simple.
So let's test
okay so this is.
And line
so ABC the perfect okay.
So what other functions do we have.
So we have one more function.
Find a 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 present I want to find a way it is ABC present in
string as food.
So how will find function works.
So suppose this is your string let's say this is the E F ABC ABC and then again ABC and if I call the
function as DART find ABC.
So basically I want to find various ABC present and this a string.
So ABC presented ABC President air ABC is presented.
So this find function will return me in Deja.
So this A.J. is actually the index.
So at index of E various this ABC present.
So this ABC is present at multiple locations so 0 1 2.
So this is index 3.
So ABC is present at index 3.
So this is four five then six seven eight.
And then this is 9 10 and 11.
So this ABC string is presented Kleenex it is present at the next three it is president I didn't take
six and it is present at the next nine so two times this is 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 a B then E B then E C and then ABC.
So if this is this thing and I call the function as dark find string ABC.
So what will be my output.
So where is ABC present so ABC is peasant head only so they index zero one two three four five and six.
So it will have done 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 am calling the find function I want to find a V
it is ABC present in string as food so it older than me n and Deja
so ABC is present at index 3 so let's see.
So this is the string as food you can see ABC so ABC is present at the next three so that's why the
output is in next three but fact so what other functions do we have we have a function to string.
So for example you have an integer e 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 e as input.
So it will have done meet the string it will convert to integer into string and let us print as six
so this s six.
This is s s six so when twenty three is now string 123 so I'm a rating myself.
So this is one twenty three in Deja This is when going between digit.
Now you are playing a function boosting and boosting function will take indeed as input.
So this boosting function it will take I Indigenous input I am giving when going to three and it will
convert the integer into listing.
So this is now string 123 fine.
So there's this thing one two or three you can change the values also because we can we can consider
we can reap the strings as if it is entity.
So when it does change the characters.
So for example I want to change the first index the character represented the first and next let's say
it is for now because it is a string.
So you have to give.
Correct.
Therefore not indigent for so this is correct for now.
And now let us also print as 6 again
so when quantity was my original string.
Now I change 2 in 2 4 so 2 is now converted into 4 so we have a function boosting similar.
You also have a function you do.
So.
So I am using E again.
So this e
so this a is actually we have a function.
You do.
Oy.
Now just do away function.
It will take a string as input and it will return within Deja.
So now let us sprint a
okay.
So I don't know in which library to a function is present.
So what I'm going to do so instead of these three
okay.
This do function is not working
okay.
So for working of this into a function I think you have to write something like this a six note C and
let's call SDR
okay.
So now it is working.
So this is a function.
What it does is it converts the given string into an integer so that you do a function it will take
a integers input.
So I am giving.
It will take a string as input.
So I'm giving a sixth.
So I'm giving 1 4.
So I'm giving when 43 and it will return me in digital 143 okay.
Now let's say if you want to insert elements so you want to insert element and is six 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 1 4 3 5.
Okay.
So let us also print a 6.
Then we will print a so after pushing 5.
Let us now print as 6.
So what is happening here.
So this was your 123 then twisting string function will convert 123 integer to 123 string then you are
changing the first character to 40 so this will become 1 40 then you are pushing 5.
So this will become 1 4 3 and 5.
You add printing a 6 so 1 4 3 5 is getting printed here.
Then you are using you to away function.
So you do a function will convert it into integer.
So this is 1 4 3 5 and then you add printing.
So it is getting printed 1 4 3 5.
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 connectivity.
Now how this things are working.
So string I told you so string is actually a plus.
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 character added only so I think I have covered many functions of the string.
So if you have any doubt and you have these functions you can ask me I will share the code with you.
So I will see you in the next one.
Bye bye.