mirror of
https://github.com/Estom/notes.git
synced 2026-02-03 18:44:19 +08:00
javascript 简单复习
This commit is contained in:
46
JavaScript/ecmascript-5/string.md
Normal file
46
JavaScript/ecmascript-5/string.md
Normal file
@@ -0,0 +1,46 @@
|
||||
## 大小写转换
|
||||
|
||||
String 对象提供如下方法,用于大小写转换。
|
||||
|
||||
| 方法名 | 说明 |
|
||||
| --- | --- |
|
||||
| toUpperCase() | 把字符串转换为大写。|
|
||||
| toLowerCase() | 把字符串转换为小写。|
|
||||
|
||||
```javascript
|
||||
var msg = 'Hello World';
|
||||
|
||||
var lowerMsg = msg.toLowerCase();
|
||||
var upperMsg = msg.toUpperCase();
|
||||
|
||||
console.log( msg );// Hello World
|
||||
console.log( lowerMsg );// hello world
|
||||
console.log( upperMsg );// HELLO WORLD
|
||||
```
|
||||
|
||||
## 获取指定位置的字符
|
||||
|
||||
String 对象提供如下方法,用于获取指定位置的字符。
|
||||
|
||||
| 方法名 | 说明 |
|
||||
| --- | --- |
|
||||
| charAt() | 返回在指定位置的字符。|
|
||||
| charCodeAt() | 返回在指定的位置的字符的 Unicode 编码。|
|
||||
|
||||
```javascript
|
||||
var str = "HELLO WORLD";
|
||||
|
||||
console.log( str.charAt(2) );// L
|
||||
console.log( str.charCodeAt(0) );// 72
|
||||
```
|
||||
|
||||
## 检索字符串
|
||||
|
||||
String 对象提供如下方法,用于检索字符串。
|
||||
|
||||
| 方法名 | 说明 |
|
||||
| --- | --- |
|
||||
| indexOf() | 返回某个指定的字符串值在字符串中首次出现的位置。|
|
||||
| lastIndexOf() | 从后向前搜索字符串。|
|
||||
|
||||
```javascript
|
||||
Reference in New Issue
Block a user