Advertisement
Coinage

Strings

May 6th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. // How to set strings
  2.  
  3. // Strings are text basically
  4.  
  5. // For example:
  6.  
  7. string text = "lalalala";   // you can put anything in the ""
  8.  
  9. // Here you have a string that is called text, and is defined as "lalalala". A string can be anything that has characters
  10.  
  11. // You can change a string by just setting it to another string  (a set of letters)
  12.  
  13. text = "hehehehe";                     // text is now heheheh
  14. text = "lolcoinageistooawesomeforme";   // text is lolcoinageistooawesomeforme
  15. text = "anything";                      // text is anything
  16.  
  17. // You can do a lot more stuff with strings, such as making the string upper case, or lower case
  18.  
  19. string lower = text.ToLower();    // ToLower is a function that turns all the characters in text to lower case (A turns into a)
  20. string upper = text.ToUpper();    // ToUpper is a function that turns all the characters in text to upper case (a turns into A)
  21.  
  22. // A string cannot be a number, that's what ints are for. You can check what a string is with a variety of functions
  23.  
  24. // Here are some if statements as examples: An if statement runs the code in the (),
  25. // and does the code in the {} if the code in () is true.
  26. text = "hellocoinage";          // text is set to "hellocoinage"
  27. if (text.StartsWith("hello"))   // If statement checks if text starts with "hello"
  28.        {
  29.           string welcome = text.ToUpper();   // If the if statement is true, then a new string is set, which is called welcome, and                      
  30.                                              // it is equal to text completely capitalized
  31.        }
  32.  
  33. text = "hmm";   // text is set to "hmm"
  34. if (text.Contains("coinage")) // If statement checks if text contains the string "coinage"
  35.       {
  36.            text = "wizard2002";     // if the if statement was true, text will be "wizard2002"
  37.       }
  38. else                                // else is used when you want the code to do something else if the if statement isn't true
  39.              {
  40.                 text = "italkalot";  // if the if statement is false, then it will set text to "italkalot"
  41.              }
  42.  
  43. // Strings are very important in coding, and are the building blocks of code, just like ints. You can do so much
  44. // with strings, such as set arrays, get characters from a string, and much more..
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement