All language subtitles for 21. Working With Strings - Part 2

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1 1

Let's continue with some simple string methods. 2

2

And the first two are gonna be 3

3

for changing the case of a string. 4

4

So that's airline.to lowercase. 5

5

And this doesn't require any arguments at all. 6

6

And then we also have to uppercase. 7

7

And these we use all the time, 8

8

as you will see soon in a more real world example. 9

9

And here you see that indeed, they transform to string, 10

10

all to lowercase, and to uppercase. 11

11

And again, you can of course, call these directly, 12

12

also on a string, so like this, all right? 13

13

But now let's use this on a more practical example, 14

14

to fix the capitalization in a passenger name. 15

15

capitalization in name, okay? 16

16

So let's say that the passenger when he checked in 17

17

I misspelled his name, and so it looks like this now. 18

18

And so this needs to be fixed, 19

19

it should look like this, okay? 20

20

So in order to fix it, the first step is usually 21

21

to put everything into lowercase here. 22

22

So const, passenger, lower 23

23

is passenger.to lowercase, like this. 24

24

Okay, so basically, we already have now this part here. 25

25

And now all we need to do is to essentially 26

26

take the first letter, and then the rest of the string 27

27

and put these two parts back together. 28

28

So passenger, correct, will be passenger lowercase. 29

29

And here, we only need the first letter. 30

30

So how do we do that, 31

31

we take the first letter by using the index zero. 32

32

And so this one, we now convert to uppercase, all right? 33

33

And now we simply need to add the rest of the string. 34

34

So, again, we take passenger lower, 35

35

and then we use the slice that we learned 36

36

in the last lecture, and start at position number one, 37

37

because remember, that will then go to index one, 38

38

and take everything until the end of the string. 39

39

And so here, we then put back together, 40

40

just the first part of the string 41

41

converted to uppercase here, and then the rest of the string 42

42

that we already had converted to lowercase before. 43

43

Now, okay, and, indeed, now it is corrected, great. 44

44

And of course, we could have done a function with this. 45

45

And so maybe if you have the time, you can do that. 46

46

So just create a function which takes any passenger name, 47

47

and then returns the correct one. 48

48

So with the fixed capitalization, but anyway, 49

49

I will now do another real life example, 50

50

which is to check a user input email, okay? 51

51

So check email, now, this will not be really a checking, 52

52

it will more be a comparing, so comparing emails. 53

53

So let's say that we have to email of one passenger. 54

54

So hello at Jonas.io, but now as the user logs in, 55

55

so let's say login email, accidentally they do it all wrong, 56

56

and they start with a couple of spaces here, 57

57

and then the capitalization is all completely off 58

58

like this, and then maybe even another space, 59

59

or even an enter character, which remember is backslash n. 60

60

So I think we talked about that in the beginning, okay? 61

61

But still, this email here is actually still kind of correct 62

62

and kind of valid. 63

63

And so we can now still compare 64

64

if these two are kind of the same, okay? 65

65

So we can now try to convert this one to this one, 66

66

and then check if they are the same. 67

67

Because essentially, again, they are, 68

68

they would be different if we had 69

69

like different letters here, then of course, 70

70

they would not be the same. 71

71

But here it's just a matter of capitalization. 72

72

And for emails I believe that they are still valid 73

73

even with the capitalization off. 74

74

And so when we check user input like this, 75

75

the first step is usually to convert it to lowercase. 76

76

So lower email, is login email.to lowercase. 77

77

And then we must also get rid of all the whitespace here. 78

78

So these empty spaces, and also this enter basically here 79

79

also counts as a whitespace. 80

80

So there is even a method for that. 81

81

So let's say, trimmed email. 82

82

And so that is lower email.trim. 83

83

All right, let's just now log this to the console 84

84

just to see. 85

85

And so that looks exactly like that first version. 86

86

Now, just look closely at what we did here. 87

87

So we called to lowercase on this login email, 88

88

stored it to this variable, 89

89

and then on that variable, we called the trim method. 90

90

But why do we even need this intermediate email?

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.