String JavaScript in () method

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>


<script>

// Create a manner
var = S "Helllo";
// Create Second way
var s2 = new String ( "hello ");

 

Attribute length String object
alert (s.length);

Traversal string:
for (var I S in) the console.log {(S [I])};

------------------------- String method ---------
scheduling method:
document.write (s.italics ());
document.write (s.bold ());
document.write (s.anchor ( "CAS")); // anchor () method is used to create HTML anchors.

Case conversion:

console.log(s.toUpperCase());
console.log(s.toLowerCase());

Gets the specified characters:


console.log(s.charAt(3));
console.log(s.charCodeAt(3));

Query String match (); search ():

console.log (s.search ( "l") ); a first index matching result of the value returned //
console.log (s.match ( "E") [0]); // Returns an array, which is All matches
console.log (s.match ( "E") [1]); // returns an array, which is all the matches

console.log (s.indexOf ( "l") ); // indexOf () method returns a string value of the specified position of the first occurrence of the string.
console.log (s.lastIndexOf ( "l") );


replace concat split

console.log(s.replace("E","e"));
console.log(s.split("E"));
console.log(s.concat(" world"))

截取字符串
console.log(s.substr(1,1));
console.log(s.substring(1,4));
console.log(s.slice(1,-1));

</script>
</body>
</html>

Guess you like

Origin www.cnblogs.com/gerenboke/p/11765521.html