Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="description" content="String Manipulation">
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>String Manipulation</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- /*String Manipulation:
- *
- *Now that we know what strings are, we can
- *start doing things to them!
- *
- *
- *The first thing we can do with strings is access
- *their different characters. Strings use zero-based
- *indexing for their individual characters, like arrays.
- */
- var name = "Roux";
- console.log(name[0]); // prints "R", because its the first character
- console.log(name[name.length-1]); // prints "x", because its the last character
- /*If you want to use punctuation in your string, you must place
- *a backslash before the punction.
- */
- var sent = "Roux said \"You silly mouse\" before she ate him."
- /*
- *There are several methods, or tools, built in that we can
- *use to manipulate our strings.
- */
- var name = "Roux";
- console.log(name.length); //prints the length(number of characters) of the string: 4
- console.log(name.slice(1,3)); //cuts out the part of the string between the indexes
- console.log(name.toUpperCase()); // prints "ROUX" - or all the characters capitalized
- console.log(name.toLowerCase()); // prints "roux" - or all the characters lower cased
- console.log(name.split("")); // creates an array of all the characters
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">/*String Manipulation:
- *
- *Now that we know what strings are, we can
- *start doing things to them!
- *
- *
- *The first thing we can do with strings is access
- *their different characters. Strings use zero-based
- *indexing for their individual characters, like arrays.
- */
- var name = "Roux";
- console.log(name[0]); // prints "R", because its the first character
- console.log(name[name.length-1]); // prints "x", because its the last character
- /*If you want to use punctuation in your string, you must place
- *a backslash before the punction.
- */
- var sent = "Roux said \"You silly mouse\" before she ate him."
- /*
- *There are several methods, or tools, built in that we can
- *use to manipulate our strings.
- */
- var name = "Roux";
- console.log(name.length); //prints the length(number of characters) of the string: 4
- console.log(name.slice(1,3)); //cuts out the part of the string between the indexes
- console.log(name.toUpperCase()); // prints "ROUX" - or all the characters capitalized
- console.log(name.toLowerCase()); // prints "roux" - or all the characters lower cased
- console.log(name.split("")); // creates an array of all the characters
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement