1 00:00:00,560 --> 00:00:02,870 Welcome back to Section four. 2 00:00:03,140 --> 00:00:06,200 Now we're going to cover lesson two string manipulation. 3 00:00:07,220 --> 00:00:10,010 So in the last lesson, we learned just what strings are there. 4 00:00:10,010 --> 00:00:13,970 Basically these lines of text in quotes, single or double quotes. 5 00:00:14,930 --> 00:00:21,020 And now we're going to learn some ways we can mess with these strings, mess with this text. 6 00:00:21,290 --> 00:00:22,700 And there are a number of ways to do that. 7 00:00:22,700 --> 00:00:29,420 So one is concatenating strings and there are a number of ways to concatenate actually, you can use 8 00:00:29,420 --> 00:00:30,470 the concat method. 9 00:00:31,500 --> 00:00:39,330 You can use the plus sign, there's also a way to do it with string interpolation, but basically you 10 00:00:39,330 --> 00:00:42,210 can do multiline strings and that's totally fine. 11 00:00:43,150 --> 00:00:49,810 And you can do template literals and expression interpellation, so we're going to look at all of that 12 00:00:49,990 --> 00:00:51,460 over here in JavaScript. 13 00:00:51,910 --> 00:00:53,190 Here's the example right here. 14 00:00:53,200 --> 00:00:59,740 So string concatenation, let's say if we started with a variable, my name is that's one string we 15 00:00:59,740 --> 00:01:01,840 can can Katani with the plus sign. 16 00:01:02,920 --> 00:01:08,020 And do an empty string there, so just a space concatenate again. 17 00:01:08,230 --> 00:01:09,880 Our final word, phyto. 18 00:01:11,220 --> 00:01:13,810 So if we do that separately, we can do. 19 00:01:13,860 --> 00:01:17,690 My name is and then string plus equals. 20 00:01:18,330 --> 00:01:21,150 So that's using the assignment operator. 21 00:01:21,150 --> 00:01:29,610 The addition assignment operator to do equals string plus that space and then string equals string plus 22 00:01:29,610 --> 00:01:30,150 phyto. 23 00:01:30,870 --> 00:01:32,350 These accomplish the same thing. 24 00:01:32,790 --> 00:01:39,120 You can also if you have two separate strings, you can concatenate multiple values using the concat 25 00:01:39,120 --> 00:01:41,660 method and the method is basically a function. 26 00:01:41,670 --> 00:01:46,260 So a block of code that you can run on a specific object. 27 00:01:46,380 --> 00:01:49,160 And this is a this is a specific object right here. 28 00:01:49,620 --> 00:01:55,130 We're going to contaminate these values and add those to string one, OK? 29 00:01:56,220 --> 00:01:58,370 So that's going to accomplish the same thing there. 30 00:01:59,690 --> 00:02:06,350 And then you can also do multiline strings, so this is where your console logging multiple lines using 31 00:02:06,350 --> 00:02:10,350 the new line character to indicate a new line. 32 00:02:11,150 --> 00:02:19,400 This backslash is useful to escape various characters for special operations like this, where you want 33 00:02:19,400 --> 00:02:27,890 to have a new line and then here you can do the same thing if you use these special back ticks right 34 00:02:27,890 --> 00:02:28,320 here. 35 00:02:28,700 --> 00:02:33,530 It's like this special quote and you're going to find this at the top left corner of your keyboard, 36 00:02:33,530 --> 00:02:34,670 just below your escape key. 37 00:02:35,330 --> 00:02:37,310 You can use this for string interpolation. 38 00:02:37,340 --> 00:02:43,490 You can also use it for multiline strings without having to use the new line character and then template 39 00:02:43,490 --> 00:02:44,060 literals. 40 00:02:44,600 --> 00:02:47,630 What this means is that you can do interpellation. 41 00:02:48,020 --> 00:02:55,040 Basically, these back ticks indicate a template and you can interpellation means you are going to reference 42 00:02:55,040 --> 00:03:05,840 some variable or other nickname property like a like a parameter or an object property directly inside 43 00:03:05,870 --> 00:03:06,620 the string. 44 00:03:06,800 --> 00:03:12,770 And you're going to use the special syntax dollar sign curly braces and then the name of the shortcut 45 00:03:12,770 --> 00:03:18,110 value like the variable, and then you end it with a curly braces right there. 46 00:03:18,110 --> 00:03:21,050 And that's the syntax for interpolating. 47 00:03:21,050 --> 00:03:23,870 So it's to put something inside of the string. 48 00:03:24,500 --> 00:03:27,650 OK, now let's take a look at all that in JavaScript. 49 00:03:29,240 --> 00:03:31,790 So let's start again with String Concat Nation. 50 00:03:32,300 --> 00:03:38,900 So let's just look at string concatenation now. 51 00:03:38,900 --> 00:03:42,080 Concatenation, really what this refers to is just. 52 00:03:43,790 --> 00:03:48,710 Piecing multiple strings together and there are a few different ways we can do this, so let's just 53 00:03:48,710 --> 00:03:49,940 start with one 54 00:03:56,750 --> 00:03:58,730 and we can say my dog's name 55 00:04:02,330 --> 00:04:04,880 plus is 56 00:04:12,920 --> 00:04:13,550 Bones. 57 00:04:14,360 --> 00:04:15,470 That's the name of my dog. 58 00:04:15,920 --> 00:04:16,370 All right. 59 00:04:17,150 --> 00:04:18,440 My dog's name is Bones. 60 00:04:19,340 --> 00:04:25,190 Now, to test this, we could go ahead and log and make sure that we're getting what we expect. 61 00:04:26,600 --> 00:04:31,310 Let's just call a long string one and save. 62 00:04:32,840 --> 00:04:33,620 And then run it. 63 00:04:35,600 --> 00:04:43,100 My dog's name is Bones, it concatenated the string together using the addition symbol right there. 64 00:04:44,660 --> 00:04:46,520 Let's try to do the same exact thing. 65 00:04:47,090 --> 00:04:48,980 Well, let's do it in a little bit different way. 66 00:04:50,120 --> 00:04:50,930 The string to. 67 00:04:52,610 --> 00:04:54,730 So let's start with again my dog's name. 68 00:04:58,880 --> 00:05:00,780 And now we're going to do something a little bit different. 69 00:05:01,490 --> 00:05:05,610 We're going to modify screen to we're going to manipulate it this way. 70 00:05:06,290 --> 00:05:09,950 So after we've previously assigned it, we're just going to do it plus equals. 71 00:05:11,000 --> 00:05:17,420 And now in this one, we're going to see is and we can do that again. 72 00:05:18,890 --> 00:05:22,520 But this time we're going to do the name of the dog at the end. 73 00:05:24,650 --> 00:05:27,410 So you can see the structure is very similar. 74 00:05:27,660 --> 00:05:38,720 OK, and this plus equals is the same as saying string two equals string two plus and then my string. 75 00:05:39,350 --> 00:05:42,050 OK, you can see those are the same. 76 00:05:42,260 --> 00:05:48,140 That's why we use this addition assignment operator to contract that process because we don't want to 77 00:05:48,140 --> 00:05:49,310 have to do the repetition. 78 00:05:49,580 --> 00:05:50,800 Don't repeat yourself. 79 00:05:50,810 --> 00:05:53,840 That's one of the principles in programming. 80 00:05:54,330 --> 00:05:55,940 Don't repeat yourself D-R. 81 00:05:55,940 --> 00:05:58,460 Why we call that the dry method. 82 00:05:59,300 --> 00:06:03,740 OK, so if we do that, we try to console along that. 83 00:06:07,160 --> 00:06:13,430 In fact, we can comment that one out, actually, let's keep that in, just so you can see there are 84 00:06:13,430 --> 00:06:14,420 two at the same time. 85 00:06:16,070 --> 00:06:17,720 So that and run it. 86 00:06:18,840 --> 00:06:24,240 So you get the same thing twice, this one right here and this one right here, the both accomplishing 87 00:06:24,240 --> 00:06:31,180 the same thing, gluing these together and now we're going to let string three equal. 88 00:06:31,830 --> 00:06:32,790 My dog's name. 89 00:06:37,710 --> 00:06:41,490 OK, and now we're going to do. 90 00:06:45,930 --> 00:06:53,820 Let string four, equal string three, dog and cat. 91 00:06:54,660 --> 00:07:01,410 It doesn't have to be string four, we could do string three again, but we do dot com cat is 92 00:07:08,650 --> 00:07:12,510 three and now is that. 93 00:07:17,440 --> 00:07:20,260 Doing string for this time, because that's the final product. 94 00:07:22,360 --> 00:07:28,330 My dog's name is Bones, OK, again, we could have just done string three would have been the same. 95 00:07:29,350 --> 00:07:31,620 You can reassign more values to. 96 00:07:33,210 --> 00:07:36,900 String theory, OK, string theory is already been declared, so we don't need to let twice. 97 00:07:41,310 --> 00:07:41,840 There you go. 98 00:07:43,020 --> 00:07:46,440 OK, so that's string concatenation, that's just gluing strings together. 99 00:07:47,610 --> 00:07:49,650 Now let's take a look at multiline strings 100 00:07:52,590 --> 00:07:53,150 strings. 101 00:07:53,450 --> 00:07:57,510 What that means is the string is going to go down onto multiple lines. 102 00:07:58,740 --> 00:08:00,300 So let's just consider 103 00:08:05,010 --> 00:08:05,880 this line. 104 00:08:10,590 --> 00:08:15,230 And now we're doing the special new line character, as you can see, it colored it differently inside 105 00:08:15,240 --> 00:08:19,500 my editor, and now we actually don't need to do anything else. 106 00:08:19,500 --> 00:08:22,530 We don't need to put this on multiple lines in our code. 107 00:08:22,530 --> 00:08:25,440 But it's useful just to know what we're what we're trying to do. 108 00:08:26,220 --> 00:08:35,700 So we can say second line, too, and that's it if we do that. 109 00:08:37,210 --> 00:08:43,810 And run it, it puts it on two separate lines, so kind of as a nice note for ourselves, we could just 110 00:08:43,810 --> 00:08:45,370 remember that that's what we're trying to do. 111 00:08:46,120 --> 00:08:47,800 And we put those on two separate lines. 112 00:08:49,770 --> 00:08:56,730 How many spaces before doesn't matter, these spaces don't mean anything, so that'll work just fine. 113 00:08:59,890 --> 00:09:09,710 And we can do a similar thing with council log, but this time we're going to use our special tactics. 114 00:09:11,580 --> 00:09:15,420 So in this case, the formating does matter. 115 00:09:15,900 --> 00:09:22,350 So we're going to we're going to see first line here and we're going to do a new line. 116 00:09:23,570 --> 00:09:27,370 And then the second one, OK. 117 00:09:31,670 --> 00:09:35,770 Here you go, one, two. 118 00:09:36,800 --> 00:09:39,800 OK, so there you go. 119 00:09:39,830 --> 00:09:45,920 So because we're using these special back ticks, it's going to remember the formatting that we've put 120 00:09:45,920 --> 00:09:47,000 in this place. 121 00:09:47,030 --> 00:09:52,130 So it's going to understand or pass the string in a slightly different way. 122 00:09:53,660 --> 00:09:54,040 All right. 123 00:09:54,140 --> 00:09:57,080 But that's how the two ways you can do multiline strings. 124 00:09:57,890 --> 00:10:00,260 So now let's learn a little bit more about template literals. 125 00:10:02,180 --> 00:10:03,800 And interpellation 126 00:10:07,700 --> 00:10:13,370 interpellation is another way you can use you can put multiple pieces of data together in strings. 127 00:10:13,790 --> 00:10:23,320 OK, for example, we're going to do let string four equal phones, OK? 128 00:10:24,110 --> 00:10:25,600 So I'm going to keep that handy. 129 00:10:25,610 --> 00:10:34,220 It's just going to be sitting right there and now we'll do a let's string five equal use these tactics. 130 00:10:35,510 --> 00:10:50,360 And we're going to do my dog's name is, and then we use our special dollar sign, Curly Braces String 131 00:10:50,480 --> 00:10:51,260 for. 132 00:10:54,050 --> 00:10:55,880 And then we end it with the back tick. 133 00:10:58,040 --> 00:10:59,600 Now, if we can't so long that 134 00:11:05,140 --> 00:11:06,320 story five 135 00:11:10,520 --> 00:11:17,640 and see what happens, what we should get is the same line again, this time using interpolation. 136 00:11:17,660 --> 00:11:20,150 So what happened here is it starts reading. 137 00:11:20,160 --> 00:11:24,140 It says sees this and says, oh, I'm going to do some special formatting in here. 138 00:11:24,650 --> 00:11:26,720 If I'm multiline, then I'll multiline. 139 00:11:27,170 --> 00:11:34,070 But if I see anything with this syntax, a dollar sign and a curly braces, I'm going to try to reference 140 00:11:34,070 --> 00:11:36,600 that information from somewhere previous in my code. 141 00:11:37,760 --> 00:11:38,420 So there you go. 142 00:11:38,420 --> 00:11:42,080 It sees that there's a string for and there's an assigned value to that. 143 00:11:42,290 --> 00:11:45,740 So it takes that assigned value and puts it right in the spot. 144 00:11:46,790 --> 00:11:53,240 OK, that's what happens when you consider the string it goes and sees, oh, what's this string defined 145 00:11:53,240 --> 00:11:58,940 as it goes and finds out, finds out that it requires another reference and then it goes and grabs that 146 00:11:59,220 --> 00:12:00,970 he puts those together and then you're done. 147 00:12:02,620 --> 00:12:04,670 So that is string manipulation. 148 00:12:05,560 --> 00:12:10,060 We used one method right here, but there are many string methods that you can look at. 149 00:12:12,040 --> 00:12:14,860 They're all here in this one resource. 150 00:12:16,020 --> 00:12:23,100 If you go to the Murdochs, you can go and see string talks all about creating strings and various different 151 00:12:23,970 --> 00:12:26,700 escape notation that you can use inside strings. 152 00:12:28,580 --> 00:12:34,340 And then multa multiple lion strings and then these different methods you can use, you can find a certain 153 00:12:34,340 --> 00:12:38,190 character at a specific index you can concatenate. 154 00:12:38,210 --> 00:12:42,080 You can find out if a string includes a certain search string. 155 00:12:42,980 --> 00:12:46,400 Find out if it ends with certain values, et cetera. 156 00:12:46,520 --> 00:12:47,870 Lots of different ways. 157 00:12:47,870 --> 00:12:52,460 You can modify information in strings, find information inside of strings. 158 00:12:53,180 --> 00:12:58,190 And so I recommend you try a lot of these different string methods in your practice. 159 00:12:58,850 --> 00:13:01,040 OK, we'll see in the next video.