---
# System prepended metadata

title: '**==小小字串篇==**'

---

# **==小小字串篇==**
toUpperCase --- 字串變大寫
toLowerCase --- 字串變小寫
```javascript=
    let str = 'Hi Im David Lee'
    let Upstr = str.toUpperCase()
    let Lowstr = str.toLowerCase()
    console.log(Upstr) // HI IM DAVID LEE
    console.log(Lowstr) // hi im david lee
````
substring / slice --- 字串切割 / 或字串擷取
```javascript=
    let str = 'HiImDavid'
    let ImDavid = str.substring(2, 9)
    let Im = str.slice(2, 4)
    console.log(ImDavid)// ImDavid
    console.log(Im)// Im
````
length 字串長度
```javascript=
    let str = 'HiImDavid'
    console.log(`${str.length}`) // 9
````
concat 字串連接，並返回一個新字串
```javascript=
    let str = 'Hi'
    let str2 = 'ImDavid'
    console.log(str.concat(str2)) // HiImDavid
````
split 字串切割變陣列
```javascript=
    let str = 'HiImDavid'
    console.log(`${str.split('')}`)
    //["H", "i", "I", "m", "D", "a", "v", "i", "d"]
````
trim 字串去頭去尾空白
```javascript=
    let str = '    HiImDavid      '
    console.log(`${str.trim()}`) // HiImDavid
````
