STRING THEORY

Let’s talk about "strings." When we talk about strings in programming, we’re generally just talking about text. For example, in our very first project, we printed out the text 'Hello, World!'  In this example, 'Hello, World!' is a string.

In fact, a string is any combination of letters, numbers and symbols that is used as text, and we typically indicate something is a string by putting quotation marks (') around it. Here are some examples of strings:

'Hello, World!'

'What is brown and sticky?  A stick!'

'4 score and 7 years ago.'

'1 2 3 4 5 6 7 8 9 10'

'My name is Jason'

'1+1'

While some of those strings contain numbers and other symbols, because they are each surrounded by quotation marks, we treat them as a single group of characters, exactly as they are.

For example, you might look at that last string ('1+1') and think to yourself, "That is the same as 2." While you’re obviously correct that 1+1 = 2, when the computer sees the quotation marks around that string, it just thinks of it as a series of three characters put together.  But, if you're wondering how to get the computer to print the value of the calculation, check out Calculations.

Just to verify this, let’s revisit our program from Project #1 and replace the string 'Hello, World!' with these other strings. While we could just replace the 'Hello, World!' string with another one in line 1 and re-run the program, we can also just add additional lines below line 1 with our new commands. Let’s take a look at how this would work…

Step #1: Enter Your Code in The Code Window

Starting on line 2 of the Code Window, add the following lines (you can either type them in or cut-and-paste as we described in Project #1):


Step #2: Run Your Code

Now that you’ve entered all of your code into the Code Window, let’s see if it works. To run the program, click on the Play icon in the Icon menu.

Step #3: Verify the "Output" of Your Code

If you’ve done everything correctly, you should see the following in your Output Window:

Hello, World!
Four score and seven years ago.
4 score and 7 years ago.
1 2 3 4 5 6 7 8 9 10
My name is Jason
1+1