‫Welcome back.
‫And this video, we are going to look at string and some of its methods.
‫So String is an object of the system string class.
‫And here in programming terms, string just means a sequence of characters.
‫And there are a bunch of functions that are inside of this class that we can use in order to manipulate
‫a string.
‫And now let's have a look at some of those.
‫So let's look at, for example, substring.
‫So substring requires an integer when you want to call this function and it is used to get the substring
‫from the string starting from the specified index.
‫So if you take, for example, a string called car and you enter substring one, what it will do is
‫it will just return R, which means the C will be taken away because we are not starting at zero, but
‫we're starting at one.
‫So basically every single character has an index and for example, C is at zero, A is at one, R is
‫at two.
‫So if we say substring one, it will just take a R instead of taking the whole car.
‫Then we have to lower that is used to convert the string to lowercase.
‫So whatever is written inside of the string will now be converted into being a lowercase sentence or
‫string at the same goes forward to upper but the other way around.
‫So now it's going to convert the string to uppercase.
‫Then we have the option to trim our string so that it is trimming, all leading and trailing whitespace
‫from the string.
‫So this is often the case when entering an email address inside of a form where you, for example,
‫by accident, have an empty space at the end when you copy it from somewhere.
‫And that is usually done by the website itself or by the form itself.
‫So you don't have to delete the white space at the end because white spaces don't really add any value
‫in email addresses, right?
‫So that's why they are taken away.
‫They're by using the trim function, for example.
‫All right.
‫So now let's look at some other methods.
‫So, for example, index of string that is used to get the first occurrence of the string or character
‫inside of another string.
‫So if you have a sentence and you want to know at which position a certain word appears, so at which
‫position inside of that sentence, then you can use index off.
‫Is now a white space returns true if the string is either null or is blank.
‫Else it returns false.
‫So this is useful if you want to check if a string has any meaningful value or not.
‫All right.
‫So now let's look at some functions here.
‫So, first of all, I have the first name called Dennis, the last name Pun, and then the full name,
‫which is concatenated.
‫So we are using the function cat which concatenate those two strings, which basically just puts them
‫together.
‫Okay.
‫So then we have Dennis punch, then we use the substring function and we give it a value of two.
‫So the output will be nice because zero what was the D?
‫One is the E and it starts from two, which is N, so it just gives us the rest of the string, which
‫is nice.
‫Then we have to lower which will output dennis so the dx will be lowercase now instead of uppercase
‫and the other way around.
‫So here to upper will just make the whole string an uppercase string as well as trim.
‫We'll just go ahead and trim all of the white spaces that we have here.
‫So the output will be ten is Pangea.
‫So it takes away those empty spaces that we have surrounding it.
‫So here for example, I'm using an empty space as well as here I also have an empty space.
‫And then we have the first name dot index of E and the output will be one because EA is at the position
‫one of the first name variable which is Dennis.
‫So D is at zero, EA is at one.
‫There we are and then is null or whitespace with the first name will output false?
‫Then there is another important method which is called format.
‫So in C-sharp, the string format method is used to insert the object or variable value inside any string.
‫With a string format, we can replace the value in the specified format.
‫So here for example, syntax is string dot format any string with the index comma object.
‫So what that will do is it will put the object into the position of index so it will replace it.
‫So let's look at an example here.
‫So we have our name, which is Dennis.
‫So this is a string that we have here and then we use string format where I just say my name is.
‫And then in those curly brackets I have zero and after the string I have comma name.
‫So name itself is also a string.
‫So here the string name will be replaced at index zero in the string and the output will be my name
‫is Dennis.
‫So we can basically just take variables and put them into a string by using the format function here.
‫This will come in very handy and we will use it every now and then.
‫All right.
‫So that's it for now.
‫Let's get back to coding.
‫See you in the next video.