Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
1
00:00:01,240 --> 00:00:05,003
Let's continue with some simple string methods.
2
2
00:00:06,780 --> 00:00:08,450
And the first two are gonna be
3
3
00:00:08,450 --> 00:00:10,943
for changing the case of a string.
4
4
00:00:14,070 --> 00:00:18,397
So that's airline.to lowercase.
5
5
00:00:20,580 --> 00:00:24,460
And this doesn't require any arguments at all.
6
6
00:00:24,460 --> 00:00:27,220
And then we also have to uppercase.
7
7
00:00:27,220 --> 00:00:28,993
And these we use all the time,
8
8
00:00:30,210 --> 00:00:34,600
as you will see soon in a more real world example.
9
9
00:00:34,600 --> 00:00:37,790
And here you see that indeed, they transform to string,
10
10
00:00:37,790 --> 00:00:41,370
all to lowercase, and to uppercase.
11
11
00:00:41,370 --> 00:00:44,120
And again, you can of course, call these directly,
12
12
00:00:44,120 --> 00:00:49,120
also on a string, so like this, all right?
13
13
00:00:52,590 --> 00:00:56,450
But now let's use this on a more practical example,
14
14
00:00:56,450 --> 00:00:59,623
to fix the capitalization in a passenger name.
15
15
00:01:02,940 --> 00:01:07,223
capitalization in name, okay?
16
16
00:01:09,720 --> 00:01:12,360
So let's say that the passenger when he checked in
17
17
00:01:12,360 --> 00:01:17,360
I misspelled his name, and so it looks like this now.
18
18
00:01:17,770 --> 00:01:19,960
And so this needs to be fixed,
19
19
00:01:19,960 --> 00:01:23,973
it should look like this, okay?
20
20
00:01:25,010 --> 00:01:28,300
So in order to fix it, the first step is usually
21
21
00:01:28,300 --> 00:01:30,373
to put everything into lowercase here.
22
22
00:01:31,820 --> 00:01:36,720
So const, passenger, lower
23
23
00:01:37,800 --> 00:01:42,800
is passenger.to lowercase, like this.
24
24
00:01:44,780 --> 00:01:49,320
Okay, so basically, we already have now this part here.
25
25
00:01:49,320 --> 00:01:51,940
And now all we need to do is to essentially
26
26
00:01:51,940 --> 00:01:55,840
take the first letter, and then the rest of the string
27
27
00:01:55,840 --> 00:01:58,203
and put these two parts back together.
28
28
00:02:00,210 --> 00:02:05,210
So passenger, correct, will be passenger lowercase.
29
29
00:02:10,080 --> 00:02:12,710
And here, we only need the first letter.
30
30
00:02:12,710 --> 00:02:14,620
So how do we do that,
31
31
00:02:14,620 --> 00:02:18,930
we take the first letter by using the index zero.
32
32
00:02:18,930 --> 00:02:23,930
And so this one, we now convert to uppercase, all right?
33
33
00:02:24,450 --> 00:02:27,733
And now we simply need to add the rest of the string.
34
34
00:02:28,760 --> 00:02:32,170
So, again, we take passenger lower,
35
35
00:02:32,170 --> 00:02:34,680
and then we use the slice that we learned
36
36
00:02:34,680 --> 00:02:38,260
in the last lecture, and start at position number one,
37
37
00:02:38,260 --> 00:02:41,680
because remember, that will then go to index one,
38
38
00:02:41,680 --> 00:02:45,423
and take everything until the end of the string.
39
39
00:02:47,240 --> 00:02:50,493
And so here, we then put back together,
40
40
00:02:51,470 --> 00:02:53,940
just the first part of the string
41
41
00:02:53,940 --> 00:02:58,030
converted to uppercase here, and then the rest of the string
42
42
00:02:58,030 --> 00:03:00,773
that we already had converted to lowercase before.
43
43
00:03:03,788 --> 00:03:08,713
Now, okay, and, indeed, now it is corrected, great.
44
44
00:03:10,510 --> 00:03:13,580
And of course, we could have done a function with this.
45
45
00:03:13,580 --> 00:03:16,550
And so maybe if you have the time, you can do that.
46
46
00:03:16,550 --> 00:03:19,810
So just create a function which takes any passenger name,
47
47
00:03:19,810 --> 00:03:22,770
and then returns the correct one.
48
48
00:03:22,770 --> 00:03:26,660
So with the fixed capitalization, but anyway,
49
49
00:03:26,660 --> 00:03:29,660
I will now do another real life example,
50
50
00:03:29,660 --> 00:03:34,120
which is to check a user input email, okay?
51
51
00:03:34,120 --> 00:03:39,120
So check email, now, this will not be really a checking,
52
52
00:03:39,320 --> 00:03:44,303
it will more be a comparing, so comparing emails.
53
53
00:03:46,200 --> 00:03:49,463
So let's say that we have to email of one passenger.
54
54
00:03:51,320 --> 00:03:56,320
So hello at Jonas.io, but now as the user logs in,
55
55
00:04:01,090 --> 00:04:06,090
so let's say login email, accidentally they do it all wrong,
56
56
00:04:07,740 --> 00:04:10,940
and they start with a couple of spaces here,
57
57
00:04:10,940 --> 00:04:14,510
and then the capitalization is all completely off
58
58
00:04:15,850 --> 00:04:19,750
like this, and then maybe even another space,
59
59
00:04:19,750 --> 00:04:24,750
or even an enter character, which remember is backslash n.
60
60
00:04:25,130 --> 00:04:28,850
So I think we talked about that in the beginning, okay?
61
61
00:04:28,850 --> 00:04:33,270
But still, this email here is actually still kind of correct
62
62
00:04:33,270 --> 00:04:35,110
and kind of valid.
63
63
00:04:35,110 --> 00:04:37,410
And so we can now still compare
64
64
00:04:37,410 --> 00:04:41,500
if these two are kind of the same, okay?
65
65
00:04:41,500 --> 00:04:45,370
So we can now try to convert this one to this one,
66
66
00:04:45,370 --> 00:04:47,170
and then check if they are the same.
67
67
00:04:48,050 --> 00:04:50,850
Because essentially, again, they are,
68
68
00:04:50,850 --> 00:04:52,420
they would be different if we had
69
69
00:04:52,420 --> 00:04:54,770
like different letters here, then of course,
70
70
00:04:54,770 --> 00:04:56,400
they would not be the same.
71
71
00:04:56,400 --> 00:04:59,580
But here it's just a matter of capitalization.
72
72
00:04:59,580 --> 00:05:02,760
And for emails I believe that they are still valid
73
73
00:05:02,760 --> 00:05:05,040
even with the capitalization off.
74
74
00:05:05,040 --> 00:05:07,950
And so when we check user input like this,
75
75
00:05:07,950 --> 00:05:11,423
the first step is usually to convert it to lowercase.
76
76
00:05:12,970 --> 00:05:17,970
So lower email, is login email.to lowercase.
77
77
00:05:24,274 --> 00:05:28,060
And then we must also get rid of all the whitespace here.
78
78
00:05:28,060 --> 00:05:33,000
So these empty spaces, and also this enter basically here
79
79
00:05:35,500 --> 00:05:37,680
also counts as a whitespace.
80
80
00:05:37,680 --> 00:05:39,933
So there is even a method for that.
81
81
00:05:41,230 --> 00:05:45,700
So let's say, trimmed email.
82
82
00:05:45,700 --> 00:05:49,763
And so that is lower email.trim.
83
83
00:05:52,560 --> 00:05:56,050
All right, let's just now log this to the console
84
84
00:05:56,050 --> 00:05:56,883
just to see.
85
85
00:05:58,170 --> 00:06:01,433
And so that looks exactly like that first version.
86
86
00:06:02,810 --> 00:06:05,900
Now, just look closely at what we did here.
87
87
00:06:05,900 --> 00:06:09,910
So we called to lowercase on this login email,
88
88
00:06:09,910 --> 00:06:11,670
stored it to this variable,
89
89
00:06:11,670 --> 00:06:15,740
and then on that variable, we called the trim method.
90
90
00:06:15,740 --> 00:06:18,953
But why do we even need this intermediate email?
8118
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.