Well, here we are in Module Six, where we're going to learn about strings, and here are the Module Six learning objectives. We're going to move back away from game of a, game development for a little while to cover some more core programming topics, but don't worry, we'll get back to it soon. So in this module, we're going to be looking at an incredibly useful data type called string. And so, the core idea. Is that strings are sequences of characters, those unicode characters that we actually talked about before. So let's just jump right in and start using strings. I have already built a small project, the console application, that we're going to use to explore some of the fundamental ideas behind strings. So one of the things that strings are really useful for is getting user input, and processing that user input in some way. So, that's what, that's what we'll be doing today is we'll be. Getting input from the user and processing it. So let's actually [NOISE] prompt for, [NOISE] and read in [NOISE] gamer tag, [NOISE] print out values [SOUND]. And that extra line that I always like to add. So, to prompt for and read in the gamertag. The first thing is the prompt. We're going to ask the user to input something. And the way we'll do that is we'll do console dot write. Now, you'll notice that I didn't do write line here, because when we prompt users for input, it's much nicer for them to be able to enter that input right after the prompt instead of on the line following the prompt. So all the prompts you ever do in console apps should use write. Not write line. I'm going to say, enter gamertag. Now you'll also notice that I haven't been polite at all. You'd think I'd say please enter gamertag because I'm asking them for a favor, to provide input to my program. However, what happens is all your prompts end up having to start with please if you go down this road and that's really actually far more irritating than you might think. So, this'll, this'll be your opportunity to be impolite in your prompts. Go ahead and just prompt away without any pleases, or thank yous, or any of that stuff. Okay. So we've done the prompt, we've displayed this prompt and what the heck? Let's actually Ctrl+F5 for console apps, let's Ctrl+F5 to see what happens. Okay, it prints the prompt But it doesn't actually give us that blank line yet. It's because it left the cursor right here, and then the write line moved it here, and then we get the press any key. So, we'll get to the point, don't worry, where we have that blank line. But it does print out the prompt properly. So now, we want to read in. The gamer tag, and the gamer tag is a sequence of characters. So we want to take [NOISE] this gamer tag, and we want to put it into a string variable. Now, you might have noticed, I said, I didn't say, string is a class. String is a reference type, it's not a value type, that's why we haven't covered it, why we didn't cover it way back in the value types. But this format of a lowercase and it turns it bright blue for a keyword instead of light blue for a class, is because strings are so commonly used that we get sort of two ways to think about them. This and this, string the class, string the data type, they're the same exact thing, so I tend to use lower case string when I'm using it as a data type. And upper case string when I'm accessing properties of the string or method of the string class but it's either personal preference or it's, you know, coding standards you have to follow in your game company or whatever. So, string; I have a string. I will call it gamer tag because it's going to store the gamer tag. So, lets use a good variable name for it. Now, we've seen this use of console before. We've used console dot write, we've used console dot write line. Here, we can use console.readline to actually read in a line from the user. So it will read in whatever keys they type up until they press Enter, and then it returns the resulting string to us. So you should go do an in-lecture quiz to demonstrate to me that you understand that idea. So, we've done that, let's, now that we've read in this value, let's actually print it out. So console dot write line. This isn't a prompt, it's output, so we'll just do write line. We'll say that we're printing out the gamer tag, I might as well just capitalize that. And then concatenate the actual gamer tag to it. So now when I Ctrl+F5, it asks me for the gamer tag, here's my gamer tag, it's an awesome one. It prints out that gamer tag, and then I get the press any key to continue. So we've now used console dot read line to read in a string, we haven't done any processing to it but we've read it in. And we're going to, and we printed it out. The next thing will be a little more interesting. So, let's prompt for and read in. Their level. Whatever that means and whatever genre of game we're building here as a console application. So let's console that right. Here's the prompt. And I'll say, enter level. And now we have a problem because a level should be an integer. There are no level 83.7 paladins so, or images, depending on your game, right. So, we want to put this into an int. But if I say int level equal console dot read line. We have a real problem. And the real problem that we have is that we're getting this compilation error that I will F6 to show you. And it says, we can't implicitly convert from a string to an integer, which makes sense, right? We've talked about data types. We've talked about type conversions and type casting. And there's no way. That it can, the compiler can figure out that a string is an integer. because a string's a bunch of characters. An integer's a bunch of bits that represent a number. So, we need to turn this string into an integer. And you might think, based on our conversation about type casting, that we could just do this. But, we can't. We cannot do a straight type cast, so we're going to have to do something else. And the something else we're going to do [NOISE] is we're going to take advantage of the fact that the int datatype, in fact, even though we've called it a value type, and we use it as a value type, it actually has, hidden behind the scenes if you will, a reference type as well. And that reference type exposes a method called parse. [SOUND] Now, the term parse comes from compiler stuff, but basically what this parse means is, take the string of characters and turn it into. It's representation as an integer, and that's probably good enough for now. Compilers, total side topic, building a compiler in a compiler class is probably one of the most useful things you'll end up doing as a programmer, because there are so many ideas. That apply throughout computer science and programming in particular. But we're not going to build a compiler today. We're just going to parse this input string into an integer and then we'll print it out. So, console.writeLine level. Like so. So I'm going to Ctrl+F5, so that's for the gamer tag, and that's for the level 30. Newb. And, there we go, it prints that stuff out. So, printing this stuff out, I'm starting to get irritated that there's no space between the input and the output, so I'll add an extra line here. But I will also point out, that that int parse thing makes an assumption about the user. And the assumption it makes about the user is that the user is not an idiot. So, in fact, if I run this, and I enter a gamer tag. And it has Level and I say Bob. Bad news. Crash. Horrible thing. Close the program. Should we debug it? No. Go online? No. There is no online solution for the user being a moron. I'm sorry. Unfortunately, searching the web won't solve this problem, right. So, a user who does not enter an integer when we're expecting an integer, given what we know now, can crash our program. So you should go do an in lecture quiz about users and their behavior and then come back. Okay. The la-, we, by the way there are ways, of course, to keep the program from crashing, we just don't know those ways yet. And we won't learn them in this course. We'll learn some. Data validation stuff, but not that particular one, but as you explore C# programming more you'll learn about something called exceptions, and we can actually handle the exception where the user is a moron and doesn't enter an integer when we asked for. For one. So let's actually do one more thing though. Let's extract the first character of the gamertag. This might be useful, if in fact we, you know. Had a friend's list, and we wanted to sort it into all the gamer tags of your friends that started with g or j or whatever. And so this could be a useful thing. And we're going to actually use, well, we know a string is a sequence of characters, so when we extract one, we'll put it into a character variable. First character. Actually, let's make that an even better variable name, it's first gamer tag character. [NOISE] And so it feels like, and there is. It feels like there should be a way that we can extract from the gamer tag a character at a particular location. And there is. We use these square brackets. And between the square brackets, we enter the index of, the location in the sequence, of the character we want to extract. And so, ignore everything you've ever learned about counting. The first character is at location zero. Because programmers start counting at zero, by gosh. And that's where the first character is. So we can extract a character using the square brackets from the sea. Bad English sentence. From the sequence of characters that are the string, we can extract a character using these square brackets. And let's print that out as well just to show that we've done that properly. But before I finish typing this and we run it, go do the in lecture quiz about extracting characters from strings. Okay, so first gamertag character. Is this. I Ctrl-F5. That started with F, pay attention to that. I'm level one. And so the first gamer tag character is. In fact, F, just as we expected. Okay, so that's it for our programming for today. I'll Ctrl-S to save all that stuff. Before I finish, I want you to go do one more in-lecture quiz. But before you do, I want to say that strings are what's called immutable. So go take the in-lecture quiz to see if you know what that means. Okay. Immutable actually means that once we have a string object, we can't change it. We can form new strings from it, and we can extract characters from it, and we can parse it into integers, and we can do all kinds of other stuff. But once we've made a string object, it can never be changed. It can't be mutated. It is Immutable. Okay, so to recap for today, strings are sequences of characters, they're really useful for getting and processing user input, and strings are immutable. Next time, we'll take a look at doing some other useful string, useful things with strings.