Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- //string declaration
- phrase1 = "He said \"Hello world\" "; //to write quotes into string use \
- phrase2 = 'Hello USA ';
- phrase3 = new String("Hello New York");
- document.write("<h3>Declaration</h3>");
- document.write("Phrase1: " + phrase1 + "<br />");
- document.write("Phrase2: " + phrase2 + "<br />");
- document.write("Phrase3: " + phrase3 + "<br />");
- document.write("Phrase1 + 2 + 3 : " + phrase1 + phrase2 + phrase3 + "<br />");
- document.write("<h3>Methods and properties</h3>");
- document.write("Phrase1 length: " + phrase1.length + "<br />");
- document.write("Phrase1 Upper Case: " + phrase1.toUpperCase() + "<br />");
- document.write("Phrase1 Lower Case: " + phrase1.toLowerCase() + "<br />");
- document.write("Phrase1 char at index 10: " + phrase1.charAt(10) + "<br />");
- document.write("Phrase1 index of \"el\": " + phrase1.indexOf("el") + "<br />");
- document.write("Phrase1 slice from index 9 to 15: " + phrase1.slice(9,15) + "<br />");
- document.write("Phrase1 replace Hello with Hi: " + phrase1.replace("Hello","Hi") + "<br />");
- array = phrase1.split(" "); //Split string and save to array
- document.write("<h3>Compare</h3>");
- phrase1 = "abcd";
- phrase2 = "Abcd";
- if (phrase1 == phrase2) {
- document.write(phrase1 + " and " + phrase2 + " are equal!" + "<br />");
- } else {
- document.write(phrase1 + " and " + phrase2 + " are NOT equal!" + "<br />");
- }
- phrase1 = "apple";
- phrase2 = "ball";
- if (phrase1 < phrase2) {
- document.write(phrase1 + " is less then " + phrase2 + "<br />");
- } else {
- document.write(phrase2 + " is less then " + pharse1);
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment