1 00:00:00,330 --> 00:00:00,810 ‫All right. 2 00:00:00,810 --> 00:00:02,820 ‫Now let's look at the other exercise. 3 00:00:02,820 --> 00:00:05,010 ‫So string challenge number two. 4 00:00:05,010 --> 00:00:09,450 ‫And the first thing we needed to do is to ask the user to enter a string. 5 00:00:09,450 --> 00:00:16,740 ‫And he would enter the string here and we store that string as input and we'll do that in the main method. 6 00:00:16,740 --> 00:00:24,870 ‫As always, this will allow us to get a user input and that will be inside of our input and then we 7 00:00:24,870 --> 00:00:26,220 ‫get another user input. 8 00:00:26,220 --> 00:00:31,740 ‫And what we want to have is we want to know the character that the person is searching for. 9 00:00:31,740 --> 00:00:37,560 ‫So enter a character to search and then the person should enter one character. 10 00:00:37,560 --> 00:00:43,230 ‫And you can see we're using char here, we're not using string, but we only want to have one character 11 00:00:43,230 --> 00:00:49,800 ‫and we create a new variable here called search input, which will be a char, so a character. 12 00:00:49,800 --> 00:00:54,990 ‫And then we get the red line and we only take the very first entry. 13 00:00:54,990 --> 00:01:02,190 ‫So we say, get me the very first character in that console, red line, because this red line is going 14 00:01:02,190 --> 00:01:03,420 ‫to return a string. 15 00:01:03,420 --> 00:01:10,980 ‫And by using the square brackets and the index that you want to have, you can get a specific position 16 00:01:10,980 --> 00:01:11,790 ‫of that string. 17 00:01:11,790 --> 00:01:16,260 ‫And in this case we get the very first character of that string. 18 00:01:16,650 --> 00:01:21,090 ‫Next, we need to get the index of the character from the string. 19 00:01:21,750 --> 00:01:27,630 ‫So let's create a new integer variable which will take care of that and it will get the. 20 00:01:28,440 --> 00:01:34,290 ‫Input index of search input and it will store that in search index. 21 00:01:34,290 --> 00:01:35,450 ‫So what is input? 22 00:01:35,460 --> 00:01:39,750 ‫Well, input is this variable here, which is our console red line. 23 00:01:39,750 --> 00:01:45,150 ‫So whatever the user entered and then we get the index of a specific character. 24 00:01:45,150 --> 00:01:51,180 ‫So if you look at index of there are multiple overloads, but one of them is that it will need a char. 25 00:01:51,180 --> 00:01:56,010 ‫So a character, if you hover over it, you can see that and you can see it returns an int. 26 00:01:56,010 --> 00:01:57,750 ‫So that's exactly what we have here. 27 00:01:57,750 --> 00:02:00,930 ‫We have an int here which is called search index. 28 00:02:00,930 --> 00:02:05,580 ‫So we take the input and we get the index of a specific character. 29 00:02:05,580 --> 00:02:11,310 ‫So we just say, okay, which position is this character for the first time within input. 30 00:02:11,310 --> 00:02:16,830 ‫So within the string that we are currently looking at and then we just want to print that out. 31 00:02:16,830 --> 00:02:17,850 ‫So let's do that. 32 00:02:18,030 --> 00:02:21,900 ‫Let's print the index as a search result on the console. 33 00:02:22,020 --> 00:02:25,080 ‫And we do that by saying index of character. 34 00:02:25,260 --> 00:02:33,990 ‫And here we say zero, which means this variable here in string is one, which is this search index. 35 00:02:34,560 --> 00:02:39,450 ‫Okay, so let's just run this and see what the result will be. 36 00:02:41,600 --> 00:02:50,900 ‫So here I'm going to enter tutorials dot EU and now I'm going to search for a dot and you can see index 37 00:02:50,900 --> 00:02:53,500 ‫of character dot in string is nine. 38 00:02:53,510 --> 00:02:54,230 ‫So we have 39 00:02:54,230 --> 00:03:00,440 ‫0123456789. 40 00:03:00,590 --> 00:03:03,590 ‫So that's going to be the index of my character. 41 00:03:03,590 --> 00:03:05,450 ‫Dot As you know, it starts with zero. 42 00:03:05,450 --> 00:03:09,500 ‫So this tutorials is going to be modest, is going to be zero. 43 00:03:10,400 --> 00:03:10,670 ‫Okay. 44 00:03:10,670 --> 00:03:12,710 ‫So that was the first part of the exercise. 45 00:03:12,710 --> 00:03:16,460 ‫Now let's get to the second one where we use concatenation. 46 00:03:16,460 --> 00:03:21,080 ‫And in order to use concatenation, we need two strings that we want to combine with each other. 47 00:03:21,080 --> 00:03:25,430 ‫And what I'm going to do is I'm going to get two strings from the user. 48 00:03:25,430 --> 00:03:29,780 ‫So first of all, I want to get the first name of the user, then I want to get the last name of the 49 00:03:29,780 --> 00:03:30,290 ‫user. 50 00:03:30,290 --> 00:03:35,720 ‫And then what I'm going to do is I'm going to concatenate them, which means I'm going to combine them 51 00:03:35,720 --> 00:03:37,340 ‫to be one string. 52 00:03:37,820 --> 00:03:39,950 ‫So let's do that. 53 00:03:39,950 --> 00:03:41,360 ‫Let's concatenate them. 54 00:03:42,320 --> 00:03:46,010 ‫By using the following code so you can see we are. 55 00:03:47,340 --> 00:03:52,050 ‫We are concatenating by using the conquest method. 56 00:03:52,050 --> 00:03:57,600 ‫And what it will do is it will concatenate multiple strings with each other, even in this case. 57 00:03:57,600 --> 00:04:00,920 ‫So it's going to take first name, whatever the user has entered. 58 00:04:00,930 --> 00:04:04,290 ‫So here we ask for the first name, then we ask for the last name. 59 00:04:04,290 --> 00:04:09,900 ‫But what we also add is an empty space in between because we don't want to have the names. 60 00:04:10,790 --> 00:04:12,630 ‫Directly after another. 61 00:04:12,650 --> 00:04:14,990 ‫But we want to have an empty space in between. 62 00:04:15,140 --> 00:04:18,320 ‫And then we just print out the full name. 63 00:04:18,320 --> 00:04:21,380 ‫And you can see it's a new variable called full name. 64 00:04:21,530 --> 00:04:26,630 ‫Of course, we could have used the concatenation directly here, or we could have just said Position 65 00:04:26,630 --> 00:04:27,870 ‫one, position two. 66 00:04:27,890 --> 00:04:34,280 ‫So there are many different options, but I wanted to you to specifically use this concrete method to 67 00:04:34,280 --> 00:04:35,420 ‫do concatenation. 68 00:04:36,130 --> 00:04:36,410 ‫Okay. 69 00:04:36,410 --> 00:04:38,270 ‫So now let's run this again. 70 00:04:40,290 --> 00:04:48,840 ‫And well we had the string example I told you then the index I'm going to use zero and then here enter 71 00:04:48,840 --> 00:04:49,560 ‫the first name. 72 00:04:49,560 --> 00:04:55,490 ‫So it's going to be Dennis last name, punch button and you can see your full name is Dennis Panopto. 73 00:04:55,560 --> 00:04:57,300 ‫Well, in my case, that's the case for you. 74 00:04:57,300 --> 00:04:58,860 ‫It's going to be a different name. 75 00:04:59,250 --> 00:04:59,700 ‫All right. 76 00:04:59,700 --> 00:05:00,480 ‫So that is it. 77 00:05:00,480 --> 00:05:03,780 ‫I hope you were successful writing this code. 78 00:05:03,780 --> 00:05:07,050 ‫And if you have another solution for this, that's fine as well. 79 00:05:07,050 --> 00:05:11,790 ‫But now you know how to specifically use concatenation with the concrete method. 80 00:05:11,790 --> 00:05:16,860 ‫And by the way, you can also see that concatenation will return a string. 81 00:05:16,860 --> 00:05:20,730 ‫So when you hover over it, it even tells you what it's going to return. 82 00:05:20,730 --> 00:05:27,930 ‫So in our case, it's going to return string zero, string one and string to concatenate it, which 83 00:05:27,930 --> 00:05:30,960 ‫just means connect it together to one string. 84 00:05:31,410 --> 00:05:31,950 ‫All right. 85 00:05:31,950 --> 00:05:33,630 ‫So that's it for this video. 86 00:05:33,660 --> 00:05:35,250 ‫I hope you were successful with this. 87 00:05:35,280 --> 00:05:36,390 ‫See you in the next one.