## STRINGS (3/19)
A string is a sequence of characters. A character is, roughly speaking, a written symbol.
Examples of characters are letters, numbers, punctuation marks(标点符号), and spaces.
String values are surrounded by either single or double quotation marks.'this is a string'
"this is also a string"
## STRING LENGTH (4/19)
You will often need to know how many characters are in a string.
For this you will use the .length property. Here's an example:
var example = 'example string';
example.length
## NOTE
Make sure there is a period between example and length.
The above code will return a number for the total number of characters in the string.
## REVISING STRINGS (5/19)
You will often need to change the contents of a string.
Strings have built-in functionality that allow you to inspect and manipulate their contents.
Here is an example using the .replace() method:
var example = 'this example exists';
example = example.replace('exists', 'is awesome');
console.log(example);
Note that to change the value that the example variable references, we need to use the equals sign again,
this time with the example.replace() method to the right of the equals sign.
本文介绍了字符串的基本概念、如何获取字符串长度及修改字符串内容的方法。通过实例演示了使用.length属性获取长度和使用.replace()方法来替换字符串中的指定内容。
237

被折叠的 条评论
为什么被折叠?



