WEBVTT 00:00:00.000 --> 00:00:04.526 This is a, going to be a very short section. I just want to add on an 00:00:04.526 --> 00:00:09.984 additional test that happens to work very well with the baby name data. So this is 00:00:09.984 --> 00:00:15.376 going to be an alternative to the == that we were using before on the 00:00:15.376 --> 00:00:20.768 baby name data. And I want to show you these functions, which are called 00:00:20.768 --> 00:00:25.960 startsWith and endsWith. And these work on strings. And to explain it, I'll just look 00:00:25.960 --> 00:00:30.720 at my code here. The way this works. Is, all this is the same as we've seen before. 00:00:30.720 --> 00:00:34.417 I opened the table, they have the loop, they have the if-statement, where I'm 00:00:34.417 --> 00:00:38.771 looking at each row. So we've just look at the task left right here. So, the first 00:00:38.771 --> 00:00:42.974 part of the task is the same as we've done before. So, I say row.getField("name") so 00:00:42.974 --> 00:00:47.127 I'm pulling the name out of the row, and that's a string. And previously we've done 00:00:47.127 --> 00:00:50.874 examples like, oh, is it equal to "Abby" or "Robert" or whatever, with the ==-test. 00:00:50.874 --> 00:00:55.279 The way these startsWith and endsWith -functions work, is the syntax is 00:00:55.279 --> 00:00:59.348 kind of funny. It has a dot... And you just tag it right on to the right hand 00:00:59.348 --> 00:01:03.787 side of the name so I get out the name and I immediately say .startsWith. And 00:01:03.787 --> 00:01:08.613 then, inside of the parenthesis for the startsWith, you could just say anything. 00:01:08.613 --> 00:01:13.622 So here I say "Ab". And what that tests is, does the name begin with the letters "Ab"? 00:01:13.622 --> 00:01:18.754 And if it does its true, the startsWith is true, and if it doesn't its false. So 00:01:18.754 --> 00:01:23.458 it kinda reads. You know, does, does, does the name start with "Ab"? So, let's just 00:01:23.458 --> 00:01:28.589 try it. So if I just run this, what you'll see is it's gone through the 2,000 rows, 00:01:28.589 --> 00:01:33.598 and it's just picked out, we're gonna see they all start with "Ab". It's just; it was 00:01:33.598 --> 00:01:41.094 true, for all of those. So whatever I type here. We're gonna get rows where the name 00:01:41.094 --> 00:01:47.482 begins with that, So, I can type... I don't know, we'll reverse it. I can type 00:01:47.482 --> 00:01:53.630 in "Ba", oh, there's not that many. Or I can type maybe just uppercase "A", not two 00:01:53.630 --> 00:02:00.264 letters. We're gonna get quite a lot, quite a lot of names, begin with "A". If I 00:02:00.264 --> 00:02:07.655 type a lower case "a" here, And I run. We actually get no output. And what's going 00:02:07.655 --> 00:02:12.312 on there is in the computer the upper case "A" and the lower case "a", those are 00:02:12.312 --> 00:02:17.459 just two different letters. And so in this data the names all begin with an upper 00:02:17.459 --> 00:02:22.422 case letter and then all the other letters are lower case. So startingWith("a") 00:02:22.422 --> 00:02:27.201 - that's a subtlety that has zero results, where's if I put an upper 00:02:27.201 --> 00:02:32.042 case "A" here and run it then we get them all. Right, and you can even see how yea, they 00:02:32.042 --> 00:02:37.128 begin with an upper case letter then later letters are lower case. So you just need 00:02:37.128 --> 00:02:45.359 to know that on the test. What else was I going to do here? Let's try "Z". So if I 00:02:45.359 --> 00:02:53.616 look for startsWith("Z"), then we get all the names; there's a few there. Or I 00:02:53.616 --> 00:03:02.081 could narrow it. I could say, oh well, maybe it has to start with "Za". Then we get fewer. And maybe I could say "Zai". 00:03:02.081 --> 00:03:07.551 Then we get down to just four, And then I could say it like, I'll say it like 00:03:07.551 --> 00:03:12.140 "Zai"... I don't know, "x". Then I run it, oh then I get naught. So its poss, it's fully 00:03:12.140 --> 00:03:16.843 possible to write a test where it's just false. For all 2000 rows and then it just 00:03:16.843 --> 00:03:21.374 prints nothing. So I'll just back it to "Zai", and then we just do those. So that 00:03:21.374 --> 00:03:26.193 the startsWith function, And for these first examples, we're always going to use 00:03:26.193 --> 00:03:30.724 it pretty much this way. So we go the row for the baby data, we get the name out, 00:03:30.724 --> 00:03:35.255 and then we immediately say .startsWith, to check the left side of the name. 00:03:35.255 --> 00:03:41.277 So, as you might guess, there's also a .endsWith that tests the other, the right 00:03:41.277 --> 00:03:46.539 hand side of the name. So if I say, endsWith("z"), I run that, oh gees, 00:03:46.539 --> 00:03:52.425 surprisingly few of those so that picks up, apparently there's only three names in 00:03:52.425 --> 00:03:57.895 this whole data set that end with "z". So I could say, or I could take multiple 00:03:57.895 --> 00:04:04.267 letters. I could say, endsWith("ly"). So a few more Or I, I'll try endsWith("la" ). And 00:04:04.267 --> 00:04:09.180 I'll run that. Oh, so then there's quite a few of those. You can see, I think these 00:04:09.180 --> 00:04:13.663 are all girl names too. I mean, that, that's just culturally the pattern in 00:04:13.663 --> 00:04:18.514 English that, girl name, or "la" is, supposed to be a girl's name. So, these 00:04:18.514 --> 00:04:23.243 are, this is just two addit-, just two additional functions. And we'll, as I was 00:04:23.243 --> 00:04:28.094 saying, we'll t end to use them for the names in the baby data set, baby data set. 00:04:28.094 --> 00:04:32.700 But they're, they're gonna allow us to do some more interesting problems.