Created
March 27, 2012 13:34
-
-
Save h4/2215903 to your computer and use it in GitHub Desktop.
JS. Объект String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Методы объекта String | |
var str="Hello world!"; | |
document.write(str.length); | |
document.write("<p>Bold: " + str.bold() + "</p>"); | |
document.write("<p>Italic: " + str.italics() + "</p>"); | |
document.write(str.match("world") + "<br />"); | |
document.write(str.match("World") + "<br />"); | |
document.write(str.indexOf("Hello") + "<br />"); | |
document.write(str.indexOf("world")); | |
var str="Visit Microsoft!"; | |
document.write(str.replace("Microsoft","W3Schools")); | |
// 2. Определение типа операционной системы | |
function sniffOs() { | |
var ua = navigator.userAgent.toLowerCase(); | |
if (ua.indexOf("win") != -1) { | |
return "Windows"; | |
} else if (ua.indexOf("linux") != -1) { | |
return "Linux"; | |
} else { | |
return "Computers"; | |
} | |
} | |
document.write(sniffOs()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment