William Rosener: Hello welcome back in this video you'll learn more about string manipulation in particular will be creating a couple of commandments The first one is going to be called count vows some allow the user in our friends and will count how many bottles are in that phrase.
William Rosener: Next moment allow the user and i'm gonna let you work on this code yourself is we're going to allow the user to enter in some phrase.
William Rosener: And we're going to count the number of first person pronouns is i'm going to press on that I would get 312 and three and so again, maybe you're an.
William Rosener: English teacher and you're trying to have your students minimize the number of first person pronouns so literally they can just copy and paste some texts in here.
William Rosener: Paragraph sentences, the pages of text, it would return, the number of first person pronouns either, but i'ma let you work on that so let's go ahead and get started here with the account balls I think having walked through cannonballs you'll use them understand how to implement this one.
William Rosener: Okay, so in the same area as you found this video you can also find a link to the interface here and then save a little time creating that.
William Rosener: So the very first step, we should probably do is take a look and see what these are called so i'm going to right click here, take a look at the properties.
William Rosener: So this is called txt phrase, and this is where my total is called lbo results plural so txt phrase and lpl results, though okay we're gonna go ahead and start off with account values.
William Rosener: So i'm gonna come right up here to the very top, and the parents are supposed to do is I declare some variables and.
William Rosener: In this case, i've really got two choices, I can either put a phone like that or I can the other way is to go like this which you cannot do is put a dash in variables can be be.
William Rosener: someone's going to go with kind of the CAP capital camel capitalization there so i've got a found i've got he found in we're going to make this simple word is going to look for the number of a's his eyes nose and us and I realized, sometimes, why can be evolved as well.
William Rosener: Okay, some simply save some space aside so i've got variables and probably the very first offense to do is come right up here and type in option explicit that with I.
William Rosener: misspelled a variable plugin a warning message so i've got them as his eyes those news there and total is going to hold the number of total now okay so we're going to go ahead and say a phone.
William Rosener: is equal to.
William Rosener: Count characters and we're going to pass it and a.
William Rosener: And this is the function that will be writing here momentarily.
William Rosener: So at this point i'm just going to go ahead and do a little copying and pasting.
William Rosener: will change this to eat.
William Rosener: You and same thing over here.
William Rosener: Okay.
William Rosener: Go ahead and add them all up.
William Rosener: And finally, the last step here on this year separate team is money to display it that's going to go in one place our total in lbo results so nothing too exciting here with declared some variables.
William Rosener: we're going to go ahead and call this function which we have to write yet we're going to look for how many days are in here at place that in the verbal a.
William Rosener: Come to ease place that in there we're going to add them all up stormin of variable called total then take that and place that in results Okay, so that was kind of the easy part now for the little bit tricky part here and that's going to be writing this function here.
William Rosener: Okay, and it's just going to be called count characters.
William Rosener: I could have called this whatever I wanted to as long as it matches So this was called count characters so I need to make sure this matches as well.
William Rosener: Okay, and as soon as I hit the enter key it automatically went ahead and close let's go to declare some variables here, the first one is going to be world of the searching with my string.
William Rosener: I found position and my counter, and this will make sense here in a second.
William Rosener: Okay yeah let's go ahead and start a little loop.
William Rosener: txt phrase, and then we'll go ahead and in the loop here.
William Rosener: Okay, so what's going to happen to me i'm getting a little example right in here i'll just type the word baseball.
William Rosener: Okay, so had the user entered baseball for per step here says okay start start searching, so the very first time i'm going to come up here i'm gonna go count characters i'm gonna be looking for.
William Rosener: A lowercase a I want to start in position one counter says okay I haven't found any yet.
William Rosener: And now what's going to happen is i'm going to go, while index is one less than the length of txt phrase, and that would be aid is one less than eight yes it's going to come on down here i'm not going to go found position.
William Rosener: i'm going to be looking for in this case, the first time i'm looking for lowercase and i'm going to start in index, which is so initially when I started position one.
William Rosener: i'm going to be looking through txt phrase.
William Rosener: i'm going to be looking for, if I hard coded I could actually put an eight here.
William Rosener: But I also want this function to be at account ease eyes nose and use so i'm just going to put ch ch ar, which is the variable that was passed to this function.
William Rosener: And i'm going to do a case insensitive search, so this is going to search for both lowercase and for both lower and upper case when you start working on your count.
William Rosener: The personal pronouns I there's a good chance you might want to put a 00 okay to That way we do a case sensitive search there.
William Rosener: Okay, so there's a what's going to happen when this command is executed i'm looking for i'm starting starting in position one.
William Rosener: i'm looking through txt phrase let's assume I was baseball, even though it was northeastern State University i'm looking for a lowercase a initially at a case insensitive search.
William Rosener: Okay assume, and I was so let's do one of these other ones here let's assume I can i'm counting the eyes.
William Rosener: And baseball if composition is equal to zero, so I was searching through it for a lowercase a lowercase a lowercase you found position is going to return zero which progress with this loop to stop.
William Rosener: And one way to make this stuff is just simply say the length.
William Rosener: phrase.
William Rosener: This one Okay, so if I had eight eight plus one, so it was index within being nine is nine less than eight know and it would stop.
William Rosener: And that actually Members come right out here, and you put in number, you want here, this is going to do is terminate.
William Rosener: Okay.
William Rosener: This means we'd have found something so first of all, and commit or killer by one.
William Rosener: So let's assume we're looking for lowercase as we're going to find one right here position to OK, now the only trick is a word we start our next search and and that's going to be.
William Rosener: found position plus one we don't want to keep on in that same boat, over and over and over again so maybe if I was searching for an e.
William Rosener: I find it at position for the next time I start in position five so i'm gonna go found position plus one, but in this case i'm looking for an A I found in position to.
William Rosener: i'm not going to say two plus one is three so the next time I search i'm going to start in position three and sure enough i'm going to find another one here later on.
William Rosener: and obviously there's my end loop here.
Okay.
William Rosener: Okay, so I have literally gone through and counted, so the first time i'm going to call count characters with an A i'm going to go through count them all up.
William Rosener: Now the tricky part here are some tricky but how do I return this value Ottoman to say count characters the name of the function is equal to shelter so what's going to happen is.
William Rosener: let's go through here with the lowercase and find one to someone go through here find two a's i'm not going to place that in count characters which comes up here and it's going to place a to someone i'm looking for a's in baseball them.
William Rosener: Okay, and that's going to be it for this particular command button so by a run that.
William Rosener: I can do everything at once it account bowels and sure enough it's going to count all 10 there.
William Rosener: So we've actually finished account bowels now and i'm gonna do is challenge you to work on the count.
William Rosener: is and what you can do is to make it a little bit simpler go ahead and search for a capital, I and the space, so I don't really like, in this case here i'm not concerned about what was before that.
William Rosener: i'm just going to look for a capital I in a space capital honest base capital on a space there, so this particular case.
William Rosener: When I hit that count eyes i'm going to find three but i'm gonna challenge you with that haven't gone through the count balls I think you guys should go to handle this count eyes, I guess next video thanks.