/* A String is a data type that feels a lot like a primitive data type like int, byte, float or boolean, but is in fact a class. It has methods that can manipulate the text and return information about the text. Because it is so fundamental to the programming language, you don't have to construct it in the normal way (String text = new String("hello!");). you can just type String text = "hello!"; Either way is fine. */ /** This demo does not produce any graphics. Run the source code in Processing and look at the console. Try to figure out why the console is displaying the resulting text. */ //Create a String class called message. String message = "Hello World!"; //also acceptable: String message = new String("Hello World!"); //print message to the console. println(message); // concatenate (a fancy word for "join together") the extra sentence by using "+". message = message + " I'm a computer and it's nice to meet you."; String iCanCount = " I'm good at counting! "; message = message + iCanCount; //Processing will automatically turn other data types into a string if you try to concatenate them. int count = 12345; message = message + count; //message has a lot of stuff added to it. Let's print it to the console. println(message); // the length() method in the String class will return the number of characters in the text. // If String s = "hello", then s.length() would return 5. int msgLength = message.length(); println("The last message was " + msgLength + " characters long."); //String variables are basically an array of characters. Each letter or symbol exists in //a unique index, just like an array. The first character is at index 0. //the charAt() method will return the character that's at the given index. char charAt10 = message.charAt(10); println("the character at index 10 is " + charAt10 + "."); //toUpperCase() will make all the letter characters into CAPITAL LETTERS, //and toLowerCase() will make all the letters lower case. String upperCase = message.toUpperCase(); println("This is all capital letters: "+upperCase); String lowerCase = message.toLowerCase(); println("This is all lower case letters: " + lowerCase); //You shouldn't use == to evaluate whether a String is the same another String. //You should use the equals() method. It will return a boolean (true / false) based on //whether the Strings are the same. String hello = "hello"; String world = "world!!"; if (hello.equals("hello")){ println(hello + " is equal to hello!"); } if (world.equals("hello")){ println(world + " is equal to hello."); } else { println(world + " does not equal hello."); }