Bill Rosener: Well, this is Dr. Bell. Welcome back in this video you'll learn about string manipulation as we recreate the application shown below. We're going to allow the user to enter a 1st name and a last name, and then we'll be extracting the 1st name. How many characters last name, and how many characters. Let's start off by taking a look at a real working example. This is just an image here, and then I'll come back to the assignment description. So here's a working working version. Here's assignment 11 Javascript. Here's the finished.
Bill Rosener: I'm gonna allow the user to enter a name. I'm gonna press extract name. It's gonna tell them, grab the 1st care I mean. Grab the 1st name, Bill. How many characters for, and then repeat that with the last name, and it needs to work on any name. So I typed in William
Bill Rosener: and press extract names. I can see it's going to grab the 1st name. How many characters and the same thing with the last name there.
Bill Rosener: Okay, then, we're gonna turn around and do this almost exact same thing in Php.
Bill Rosener: a user can enter a name and press extract name. It's going to grab the 1st name. How many characters last? Name? How many characters there?
Bill Rosener: Okay, coming back here, I'm going to be walking through some code here pretty quickly.
Bill Rosener: of the Javascript. Here it is. If I press here, here's the Javascript code I'll be looking at, and then also the Php code. And there it is. So if you literally just.
Bill Rosener: we're able to key that in without any errors, get that work, and you're going to get 18 points. If you want to challenge yourself.
Bill Rosener: then go ahead. This is going to get you 20 points. Allow a middle name. So Blake, Adam Smith, it would extract the 1st name, the middle name, and the last name, and say, how many characters on each one of those names?
Bill Rosener: Okay. Now that we know what we're doing, let's get started. So the 1st step I'm gonna do is open up visual studio code. I'm gonna come right up here to file new text file.
Bill Rosener: Go ahead and grab some code here, and then we'll explain it.
Bill Rosener: Okay, so here's the the code. Maybe I'll come down here to the form. 1st of all. So I'm gonna start the form. I'm gonna close the form.
Bill Rosener: I'm going to allow the user to
Bill Rosener: input a name in this case. I've already got Bill Rosen in there. So once I've got this work.
Bill Rosener: strip that out or definitely put your name in there.
Bill Rosener: I'm then going to. And when the user presses on extract name, it's going to call the Javascript function extract name.
Bill Rosener: And then I'm going to display the results in a text area.
Bill Rosener: So coming up here, taking a look at
Bill Rosener: my function, here is extract name. I'm going to declare some variables. These 2 lines here with 0 through 0 1, 2, 3, 4, 5. Those are just some comments of those 2 slashes in the beginning. So what am I going to do? Here's kind of the really 1st line. I'm going to find this space position. So in my name.
Bill Rosener: the space would be at Position 4. So Javascript starts counting up 0 0, 1, 2, 3, 4. So I find the space at Position 4.
Bill Rosener: This line here is going to start in position, 0 going to 4. And if that grabbing the 1st
Bill Rosener: 4 characters, BILL. Storing that in 1st name
Bill Rosener: this line is also going to extract. Find the length, using 1st name dot length and then the 2 slashes on the N slash, N slash, N are new lines. Then I'm going to come down here and notice that space position plus one. So I found I came back up here.
Bill Rosener: If I take a look, I found the space in position 4. So I'm going to go. 4 plus one is 5. I'm going to start in position 5 going to the end. That's going to be last name.
Bill Rosener: So I simply keep adding, I keep creating this string called temp string, adding to it. And then, finally, last thing I'm going to do is say, document form one results equal temp string. So I'm going to say, results form one. Dot results is equal to temp string. Let me go ahead and save this. I'm going to come right up here to file. I'm going to go to save as.
Bill Rosener: and I'm gonna choose my desktop
Bill Rosener: and temp. And that's when we looked at that one just a second ago.
Bill Rosener: and I'll save a little type in here.
Bill Rosener: I'm just gonna delete the finished and save.
Bill Rosener: Okay, I can now right click over here open in default, Browser and I can put
Bill Rosener: I can put William in here, Warner Smith.
Bill Rosener: and hit extract name, and sure enough, it extracted the correct 1st name and last name, and tell me how many characters were in each one of those.
Bill Rosener: Okay, that was Javascript. And now let's go ahead and do this exact same thing using Psp, so I'm gonna come right up here, go to file new text file.
Bill Rosener: Let me grab some code here.
Bill Rosener: paste it.
Bill Rosener: And we're going to say, see, the form looks very, very similar. It's going to be called Php. Self. So we can call itself over and over if I change the information in that text box which is being stored as complete name.
Bill Rosener: So take a look here very similar. Here.
Bill Rosener: I'll be here tomorrow. We really jump in. This thing is going to find the string position. It's looking for a space. I'm going to find that
Bill Rosener: I'm now going to go from 0 to that. So let's assume it was Bill, like, maybe 0 to 4. I'm going to go use the substring grab that information. And if I found the space. That position 4. I'm starting 4 plus one is 5. Grab the last name, then what I'm doing is, you notice here, Temp, string starts out as the null string. I just keep adding to it, adding to it, adding to it, and that's what this concatenation is going to be doing.
Bill Rosener: The concatenation is going to say what is currently I got 2 options here. I can say, temp string equals temp string concatenated with something, or I can say, temp string equals dot equal, which is going to take itself and add additional information to it. So I build this
Bill Rosener: string called temp string, and then finally, I'm going to echo or display that into my text area tag and let me go ahead and save this one.
Bill Rosener: And we'll say this one as assignment 11 php.
Bill Rosener: dot, Simon, 11. Dash, php, dot, php, and here it is, and just to make sure string manipulation, I'll just go ahead and put a dash 2 here.
Bill Rosener: or maybe I'll type in. I'll just type in new
Bill Rosener: and let me go ahead and save that.
Bill Rosener: Okay, if I come over here to my Ftp for uploading. I'm gonna come here and refresh.
Bill Rosener: I can see I've got my new files here.
Bill Rosener: I'm gonna highlight these 2 files and upload those.
Bill Rosener: Okay. Then I can come along over here.
Bill Rosener: I can strip this off.
Bill Rosener: And here's the assignment level. And I just got done creating
Bill Rosener: because I can see the word new up here, and I can type in some text and hit extract.
Bill Rosener: And sure enough, that's working. So again, take a look at assignment description. I have given you the code. Here's the Javascript. Here's the Php. Code again. That's in an image format. So you'd have to type it in. And if you do that, you're going to get 18 points. If you want to challenge yourself and get the full 20 points, go ahead and see if you can also have a middle name and extract that as well. Well, I'll catch you in the next video. Thanks a lot. Man.