String objects have been used in previous studies. The way to define a string is to assign a value directly. For example:
<span style="color: #0000ff;">var</span> mystr = "I love JavaScript!"
After defining the mystr string, we can access its properties and methods.
Access the property length of the string object:
stringObject.length; Returns the length of the string.
<span style="color: #0000ff;">var</span> mystr="Hello World!"<span style="color: #000000;">; </span><span style="color: #0000ff;">var</span> myl=mystr.length;
After the above code is executed, the value of myl will be: 12
Methods to access string objects:
Use the String object’s toUpperCase() method to convert string lowercase letters to uppercase:
<span style="color: #0000ff;">var</span> mystr="Hello world!"<span style="color: #000000;">; </span><span style="color: #0000ff;">var</span> mynum=mystr.toUpperCase();
以上代码执行后,mynum 的值是:HELLO WORLD!<br><br><strong><span style="font-size: 15px;">使用String对象的toLowerCase()方法来将字符串大写字母转换为小写</span></strong>