1 00:00:00,150 --> 00:00:00,480 All right. 2 00:00:00,480 --> 00:00:05,910 Next up, there's a few other string methods or string functions that I think are worth knowing, but 3 00:00:05,910 --> 00:00:09,370 I'm going to hit them quickly and not make you watch a separate video for each one. 4 00:00:09,390 --> 00:00:11,120 The first one is called Inserts. 5 00:00:11,130 --> 00:00:15,240 It allows us to insert some substring into a larger string. 6 00:00:15,270 --> 00:00:20,070 It doesn't actually have to be a larger string, but some string into another string at the beginning, 7 00:00:20,070 --> 00:00:21,390 in the middle at the end. 8 00:00:21,390 --> 00:00:27,800 So it's different than replace because replace is going to replace some existing characters with insert. 9 00:00:27,810 --> 00:00:31,700 We can replace characters or we can simply add on. 10 00:00:31,710 --> 00:00:36,480 So let's say that I had this string not replace insert. 11 00:00:37,320 --> 00:00:40,740 How about Hello Bobby like that? 12 00:00:40,740 --> 00:00:45,360 And I want to insert something right there where the space is. 13 00:00:45,360 --> 00:00:46,410 How about there? 14 00:00:46,410 --> 00:00:48,210 So it's Hello there, Bobby. 15 00:00:48,330 --> 00:00:49,620 Very contrived example. 16 00:00:49,620 --> 00:00:51,870 Of course we would just type that string. 17 00:00:51,870 --> 00:00:56,910 But imagine I'm doing this on every single row in a table for some column. 18 00:00:56,910 --> 00:00:57,480 So. 19 00:00:57,480 --> 00:00:58,260 Hello, Space. 20 00:00:58,260 --> 00:00:58,860 Bobby. 21 00:00:58,860 --> 00:01:03,660 I'm going to say I want to insert something at this position, so I have to count. 22 00:01:03,660 --> 00:01:06,510 One, two, three, four, five, six. 23 00:01:06,510 --> 00:01:08,460 So it depends on how I want to do this. 24 00:01:08,460 --> 00:01:11,220 If I do six, let me just show you what happens. 25 00:01:11,910 --> 00:01:16,710 There's a second number I have to provide, which is the number of characters I want to replace. 26 00:01:16,710 --> 00:01:22,800 And in my example here, I don't want to replace any characters I'm adding on, but I'll show you what 27 00:01:22,800 --> 00:01:23,940 happens if we change that. 28 00:01:23,940 --> 00:01:26,610 And then what am I adding on there? 29 00:01:26,610 --> 00:01:27,630 The string there. 30 00:01:27,960 --> 00:01:29,490 So this is what we get. 31 00:01:29,490 --> 00:01:30,150 Hello. 32 00:01:30,150 --> 00:01:37,020 And then there, that whole string was inserted right at this position and then the space is still preserved 33 00:01:37,020 --> 00:01:38,370 and then we have Bobby. 34 00:01:38,580 --> 00:01:42,450 But I could have rewritten it so it had a space at the beginning. 35 00:01:42,450 --> 00:01:43,980 So we get Hello there, Bobby. 36 00:01:43,980 --> 00:01:50,160 But let me show you what happens now if we instead say replace some characters. 37 00:01:50,340 --> 00:01:56,280 So instead of just saying replace nothing and insert there at index or position six. 38 00:01:56,280 --> 00:01:58,080 What if I say replace? 39 00:01:58,410 --> 00:02:00,030 I don't know four characters? 40 00:02:00,390 --> 00:02:06,000 This is what we get it replaced for characters, so it inserted there. 41 00:02:06,000 --> 00:02:09,720 But as it did that, it replaced the Bobby. 42 00:02:09,900 --> 00:02:15,720 Or if I did it, I don't know, let's replace six characters now we just have Hello there. 43 00:02:15,720 --> 00:02:17,670 We replaced all of Bobby. 44 00:02:17,880 --> 00:02:19,260 So that's insert. 45 00:02:19,500 --> 00:02:24,660 If you're just trying to replace something like for like replace all examples of something within a 46 00:02:24,660 --> 00:02:27,000 string, then you can do that using replace. 47 00:02:27,000 --> 00:02:31,350 If you want to insert something in the middle at the beginning, at the end you can use insert. 48 00:02:31,380 --> 00:02:33,450 It is a little confusing with those two numbers. 49 00:02:33,450 --> 00:02:35,970 Just remember this is where something will be inserted. 50 00:02:35,970 --> 00:02:39,680 The second number is how many characters to replace OC. 51 00:02:39,780 --> 00:02:43,200 The next function I want to talk about is left. 52 00:02:43,590 --> 00:02:49,980 Left and right are functions we can use to get the leftmost and right most characters from some string. 53 00:02:49,980 --> 00:02:57,690 So in this case we're getting the leftmost five left most characters from foo bar bar, which is FUBAR. 54 00:02:58,080 --> 00:03:00,150 One, two, 345. 55 00:03:00,570 --> 00:03:02,550 I'll just show that really quickly. 56 00:03:02,550 --> 00:03:05,580 Select left of the string. 57 00:03:05,580 --> 00:03:11,520 OMG haha lol exclamation point I say how many left? 58 00:03:11,520 --> 00:03:13,140 Let's get the three left. 59 00:03:13,140 --> 00:03:21,390 Most characters add my semicolon and we get OMG and if I instead did right and get the three rightmost 60 00:03:21,390 --> 00:03:25,680 characters, well it's going to be all exclamation point. 61 00:03:26,070 --> 00:03:32,610 So let's maybe get the four rightmost characters and we get lol exclamation point. 62 00:03:32,940 --> 00:03:39,540 So we could have used this for example, to get the initials or create the initials of our authors. 63 00:03:39,540 --> 00:03:44,070 Let me just get let's say we want the last name, the first character of the last name, what we could 64 00:03:44,070 --> 00:03:55,500 do Select left of Author L Name one character from the left, meaning the first character from books. 65 00:03:55,740 --> 00:03:57,930 And we get L right. 66 00:03:57,930 --> 00:03:59,130 That's Lahiri. 67 00:03:59,130 --> 00:04:01,590 G is for Gaiman and so on. 68 00:04:02,640 --> 00:04:04,830 So that's left and right. 69 00:04:04,830 --> 00:04:08,100 We also have repeat, repeat does what it sounds like. 70 00:04:08,100 --> 00:04:13,470 You take some string and a number and you'll get that same string repeated that number of times. 71 00:04:14,010 --> 00:04:17,970 So if I have a string, select, repeat, huh? 72 00:04:18,660 --> 00:04:20,339 Four times we get. 73 00:04:20,370 --> 00:04:21,570 Ha ha ha ha. 74 00:04:22,230 --> 00:04:24,030 So I think that's all I need to show. 75 00:04:24,030 --> 00:04:26,520 You could use that, of course, with a real table. 76 00:04:26,520 --> 00:04:28,200 That's why you would use this. 77 00:04:28,200 --> 00:04:33,300 You probably don't need to repeat half four times, but for the sake of your own time, I'm not going 78 00:04:33,300 --> 00:04:34,620 to show an example of that. 79 00:04:34,620 --> 00:04:37,110 And the last one I'll show you is trim. 80 00:04:37,500 --> 00:04:42,210 Trim is used to remove usually spaces that are leading and trailing. 81 00:04:42,210 --> 00:04:46,260 So if I have some data that is messy, maybe it has. 82 00:04:46,770 --> 00:04:51,750 Let's just do a trim on some string that has some extra space around somebody's city. 83 00:04:51,750 --> 00:04:54,630 How about Boston and then a space at the end? 84 00:04:55,110 --> 00:04:56,760 I don't want that space there. 85 00:04:56,760 --> 00:04:59,910 If I trim it, it removes the leading. 86 00:04:59,980 --> 00:05:03,820 And trailing spaces, but it's not going to remove the spaces in the middle. 87 00:05:03,820 --> 00:05:05,890 Like if I had San Antonio. 88 00:05:07,150 --> 00:05:08,680 It doesn't remove all spaces. 89 00:05:08,680 --> 00:05:09,940 It's not a replace. 90 00:05:09,940 --> 00:05:13,870 It is simply removing, leading and trailing spaces. 91 00:05:14,200 --> 00:05:20,830 But we can actually trim other characters if you specify a certain character. 92 00:05:20,830 --> 00:05:24,520 So here they call it remove string or rim string. 93 00:05:24,880 --> 00:05:32,290 So something like this right here we can say trim the leading x characters from this string. 94 00:05:32,290 --> 00:05:35,590 It's kind of weird, the syntax, writing, leading and from. 95 00:05:35,590 --> 00:05:37,570 But let's just take a look at an example. 96 00:05:37,570 --> 00:05:40,990 Maybe I have something that looks like this. 97 00:05:41,530 --> 00:05:47,470 For whatever reason, there's a bunch of leading dots periods and trailing dots. 98 00:05:47,470 --> 00:05:51,010 Well, if I do that, it's going to look for spaces on its own. 99 00:05:51,010 --> 00:05:52,210 That's not what I want. 100 00:05:52,210 --> 00:05:58,810 I'm going to say trim leading period characters from that string. 101 00:05:58,810 --> 00:05:59,740 And there we are. 102 00:05:59,740 --> 00:06:01,900 It only trimmed the leading ones. 103 00:06:01,900 --> 00:06:06,070 If I instead had said Select trim, trailing. 104 00:06:08,100 --> 00:06:10,950 It will only remove the trailing dots. 105 00:06:10,950 --> 00:06:16,260 And then I could also say both to remove both leading and trailing periods. 106 00:06:16,410 --> 00:06:17,040 All right. 107 00:06:17,040 --> 00:06:20,820 So that's it for this wrap up of some additional string functions.