Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="description" content="String Manipulation">
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <title>String Manipulation</title>
  8. </head>
  9. <body>
  10.  
  11. <script id="jsbin-javascript">
  12. /*String Manipulation:
  13. *
  14. *Now that we know what strings are, we can
  15. *start doing things to them!
  16. *
  17. *
  18. *The first thing we can do with strings is access
  19. *their different characters. Strings use zero-based
  20. *indexing for their individual characters, like arrays.
  21. */
  22.  
  23. var name = "Roux";
  24. console.log(name[0]); // prints "R", because its the first character
  25. console.log(name[name.length-1]); // prints "x", because its the last character
  26.  
  27. /*If you want to use punctuation in your string, you must place
  28. *a backslash before the punction.
  29. */
  30. var sent = "Roux said \"You silly mouse\" before she ate him."
  31.  
  32.  
  33. /*
  34. *There are several methods, or tools, built in that we can
  35. *use to manipulate our strings.
  36. */
  37.  
  38. var name = "Roux";
  39.  
  40. console.log(name.length); //prints the length(number of characters) of the string: 4
  41.  
  42. console.log(name.slice(1,3)); //cuts out the part of the string between the indexes
  43.  
  44. console.log(name.toUpperCase()); // prints "ROUX" - or all the characters capitalized
  45.  
  46. console.log(name.toLowerCase()); // prints "roux" - or all the characters lower cased
  47.  
  48. console.log(name.split("")); // creates an array of all the characters
  49. </script>
  50.  
  51.  
  52.  
  53. <script id="jsbin-source-javascript" type="text/javascript">/*String Manipulation:
  54. *
  55. *Now that we know what strings are, we can
  56. *start doing things to them!
  57. *
  58. *
  59. *The first thing we can do with strings is access
  60. *their different characters. Strings use zero-based
  61. *indexing for their individual characters, like arrays.
  62. */
  63.  
  64. var name = "Roux";
  65. console.log(name[0]); // prints "R", because its the first character
  66. console.log(name[name.length-1]); // prints "x", because its the last character
  67.  
  68. /*If you want to use punctuation in your string, you must place
  69. *a backslash before the punction.
  70. */
  71. var sent = "Roux said \"You silly mouse\" before she ate him."
  72.  
  73.  
  74. /*
  75. *There are several methods, or tools, built in that we can
  76. *use to manipulate our strings.
  77. */
  78.  
  79. var name = "Roux";
  80.  
  81. console.log(name.length); //prints the length(number of characters) of the string: 4
  82.  
  83. console.log(name.slice(1,3)); //cuts out the part of the string between the indexes
  84.  
  85. console.log(name.toUpperCase()); // prints "ROUX" - or all the characters capitalized
  86.  
  87. console.log(name.toLowerCase()); // prints "roux" - or all the characters lower cased
  88.  
  89. console.log(name.split("")); // creates an array of all the characters
  90. </script></body>
  91. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement