Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // How to set strings
- // Strings are text basically
- // For example:
- string text = "lalalala"; // you can put anything in the ""
- // Here you have a string that is called text, and is defined as "lalalala". A string can be anything that has characters
- // You can change a string by just setting it to another string (a set of letters)
- text = "hehehehe"; // text is now heheheh
- text = "lolcoinageistooawesomeforme"; // text is lolcoinageistooawesomeforme
- text = "anything"; // text is anything
- // You can do a lot more stuff with strings, such as making the string upper case, or lower case
- string lower = text.ToLower(); // ToLower is a function that turns all the characters in text to lower case (A turns into a)
- string upper = text.ToUpper(); // ToUpper is a function that turns all the characters in text to upper case (a turns into A)
- // A string cannot be a number, that's what ints are for. You can check what a string is with a variety of functions
- // Here are some if statements as examples: An if statement runs the code in the (),
- // and does the code in the {} if the code in () is true.
- text = "hellocoinage"; // text is set to "hellocoinage"
- if (text.StartsWith("hello")) // If statement checks if text starts with "hello"
- {
- string welcome = text.ToUpper(); // If the if statement is true, then a new string is set, which is called welcome, and
- // it is equal to text completely capitalized
- }
- text = "hmm"; // text is set to "hmm"
- if (text.Contains("coinage")) // If statement checks if text contains the string "coinage"
- {
- text = "wizard2002"; // if the if statement was true, text will be "wizard2002"
- }
- else // else is used when you want the code to do something else if the if statement isn't true
- {
- text = "italkalot"; // if the if statement is false, then it will set text to "italkalot"
- }
- // Strings are very important in coding, and are the building blocks of code, just like ints. You can do so much
- // with strings, such as set arrays, get characters from a string, and much more..
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement