1 00:00:00,150 --> 00:00:01,010 ‫Welcome back. 2 00:00:01,020 --> 00:00:05,700 ‫And this video, we are going to look at string and some of its methods. 3 00:00:05,700 --> 00:00:09,810 ‫So String is an object of the system string class. 4 00:00:09,810 --> 00:00:14,280 ‫And here in programming terms, string just means a sequence of characters. 5 00:00:14,400 --> 00:00:21,240 ‫And there are a bunch of functions that are inside of this class that we can use in order to manipulate 6 00:00:21,240 --> 00:00:22,020 ‫a string. 7 00:00:22,200 --> 00:00:24,090 ‫And now let's have a look at some of those. 8 00:00:24,090 --> 00:00:27,000 ‫So let's look at, for example, substring. 9 00:00:27,000 --> 00:00:33,660 ‫So substring requires an integer when you want to call this function and it is used to get the substring 10 00:00:33,660 --> 00:00:37,680 ‫from the string starting from the specified index. 11 00:00:38,710 --> 00:00:46,390 ‫So if you take, for example, a string called car and you enter substring one, what it will do is 12 00:00:46,390 --> 00:00:54,700 ‫it will just return R, which means the C will be taken away because we are not starting at zero, but 13 00:00:54,700 --> 00:00:55,830 ‫we're starting at one. 14 00:00:55,840 --> 00:01:02,740 ‫So basically every single character has an index and for example, C is at zero, A is at one, R is 15 00:01:02,740 --> 00:01:03,370 ‫at two. 16 00:01:03,370 --> 00:01:09,790 ‫So if we say substring one, it will just take a R instead of taking the whole car. 17 00:01:10,990 --> 00:01:15,250 ‫Then we have to lower that is used to convert the string to lowercase. 18 00:01:15,250 --> 00:01:21,130 ‫So whatever is written inside of the string will now be converted into being a lowercase sentence or 19 00:01:21,130 --> 00:01:24,640 ‫string at the same goes forward to upper but the other way around. 20 00:01:24,640 --> 00:01:27,790 ‫So now it's going to convert the string to uppercase. 21 00:01:27,970 --> 00:01:35,590 ‫Then we have the option to trim our string so that it is trimming, all leading and trailing whitespace 22 00:01:35,590 --> 00:01:36,670 ‫from the string. 23 00:01:36,670 --> 00:01:43,930 ‫So this is often the case when entering an email address inside of a form where you, for example, 24 00:01:43,930 --> 00:01:48,160 ‫by accident, have an empty space at the end when you copy it from somewhere. 25 00:01:48,160 --> 00:01:53,770 ‫And that is usually done by the website itself or by the form itself. 26 00:01:53,770 --> 00:01:59,980 ‫So you don't have to delete the white space at the end because white spaces don't really add any value 27 00:01:59,980 --> 00:02:00,970 ‫in email addresses, right? 28 00:02:00,970 --> 00:02:03,520 ‫So that's why they are taken away. 29 00:02:03,520 --> 00:02:05,830 ‫They're by using the trim function, for example. 30 00:02:06,370 --> 00:02:06,730 ‫All right. 31 00:02:06,730 --> 00:02:08,170 ‫So now let's look at some other methods. 32 00:02:08,170 --> 00:02:14,860 ‫So, for example, index of string that is used to get the first occurrence of the string or character 33 00:02:14,860 --> 00:02:16,630 ‫inside of another string. 34 00:02:16,630 --> 00:02:24,190 ‫So if you have a sentence and you want to know at which position a certain word appears, so at which 35 00:02:24,190 --> 00:02:29,200 ‫position inside of that sentence, then you can use index off. 36 00:02:30,800 --> 00:02:35,630 ‫Is now a white space returns true if the string is either null or is blank. 37 00:02:35,660 --> 00:02:36,890 ‫Else it returns false. 38 00:02:36,890 --> 00:02:42,770 ‫So this is useful if you want to check if a string has any meaningful value or not. 39 00:02:43,070 --> 00:02:43,490 ‫All right. 40 00:02:43,490 --> 00:02:45,340 ‫So now let's look at some functions here. 41 00:02:45,350 --> 00:02:51,200 ‫So, first of all, I have the first name called Dennis, the last name Pun, and then the full name, 42 00:02:51,200 --> 00:02:53,000 ‫which is concatenated. 43 00:02:53,000 --> 00:02:59,870 ‫So we are using the function cat which concatenate those two strings, which basically just puts them 44 00:02:59,870 --> 00:03:00,680 ‫together. 45 00:03:01,160 --> 00:03:01,330 ‫Okay. 46 00:03:01,370 --> 00:03:07,220 ‫So then we have Dennis punch, then we use the substring function and we give it a value of two. 47 00:03:07,250 --> 00:03:11,620 ‫So the output will be nice because zero what was the D? 48 00:03:11,750 --> 00:03:18,470 ‫One is the E and it starts from two, which is N, so it just gives us the rest of the string, which 49 00:03:18,470 --> 00:03:19,130 ‫is nice. 50 00:03:19,520 --> 00:03:25,970 ‫Then we have to lower which will output dennis so the dx will be lowercase now instead of uppercase 51 00:03:25,970 --> 00:03:27,620 ‫and the other way around. 52 00:03:27,620 --> 00:03:34,900 ‫So here to upper will just make the whole string an uppercase string as well as trim. 53 00:03:34,910 --> 00:03:38,390 ‫We'll just go ahead and trim all of the white spaces that we have here. 54 00:03:38,390 --> 00:03:40,370 ‫So the output will be ten is Pangea. 55 00:03:40,400 --> 00:03:44,420 ‫So it takes away those empty spaces that we have surrounding it. 56 00:03:44,420 --> 00:03:49,460 ‫So here for example, I'm using an empty space as well as here I also have an empty space. 57 00:03:50,120 --> 00:03:58,040 ‫And then we have the first name dot index of E and the output will be one because EA is at the position 58 00:03:58,040 --> 00:04:01,220 ‫one of the first name variable which is Dennis. 59 00:04:01,220 --> 00:04:03,770 ‫So D is at zero, EA is at one. 60 00:04:03,980 --> 00:04:10,100 ‫There we are and then is null or whitespace with the first name will output false? 61 00:04:10,520 --> 00:04:13,520 ‫Then there is another important method which is called format. 62 00:04:13,790 --> 00:04:20,660 ‫So in C-sharp, the string format method is used to insert the object or variable value inside any string. 63 00:04:20,780 --> 00:04:25,100 ‫With a string format, we can replace the value in the specified format. 64 00:04:25,100 --> 00:04:33,260 ‫So here for example, syntax is string dot format any string with the index comma object. 65 00:04:33,260 --> 00:04:40,520 ‫So what that will do is it will put the object into the position of index so it will replace it. 66 00:04:41,150 --> 00:04:42,890 ‫So let's look at an example here. 67 00:04:42,890 --> 00:04:45,920 ‫So we have our name, which is Dennis. 68 00:04:46,040 --> 00:04:51,890 ‫So this is a string that we have here and then we use string format where I just say my name is. 69 00:04:51,890 --> 00:05:00,650 ‫And then in those curly brackets I have zero and after the string I have comma name. 70 00:05:00,650 --> 00:05:02,600 ‫So name itself is also a string. 71 00:05:02,600 --> 00:05:09,290 ‫So here the string name will be replaced at index zero in the string and the output will be my name 72 00:05:09,290 --> 00:05:10,430 ‫is Dennis. 73 00:05:11,420 --> 00:05:17,570 ‫So we can basically just take variables and put them into a string by using the format function here. 74 00:05:17,900 --> 00:05:21,170 ‫This will come in very handy and we will use it every now and then. 75 00:05:21,590 --> 00:05:22,190 ‫All right. 76 00:05:22,190 --> 00:05:23,210 ‫So that's it for now. 77 00:05:23,210 --> 00:05:24,530 ‫Let's get back to coding. 78 00:05:24,680 --> 00:05:25,700 ‫See you in the next video.