---
# System prepended metadata

title: 字串處理
tags: [JS 直播班 - 2022 秋季班]

---

---
tags: JS 直播班 - 2022 秋季班
---
###### tags: `簡單`
# 字串處理

## 本章節我們要學什麼？
學習練習基礎常見的字串處理方法。

### 提示
如沒有概念可以引用哪些方法來達成這次題目的目的，可以試試看……
1. 閱讀、搜尋文檔：[JavaScript 字符串方法](https://www.w3school.com.cn/js/js_string_methods.asp)、[Mozilla MDN String](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/String)。
2. 在本文件最下方參考同學們的解答。

### 題目一：字串取長度

``` =JavaScrip
// input 輸入
checkStringLength("Hello")
checkStringLength("my name is Tom！")

// output 輸出
5
15
```
### 題目二：字串大小寫互換
``` =JavaScript
// input 輸入
lowerCase("FOKFF@gmail.com")
upperCase("hello, world")

// output 輸出
"fokff@gmail.com"
"HELLO, WORLD"
```

### 題目三：字串去左右空白

``` =JavaScript
// input 輸入
trimString("    hi, mom!  ")
trimString(" aa@gmail.com  ")

// output 輸出
"hi, mom!"
"aa@gmail.com"
```

### 題目四：字串去任何空白

``` =JavaScript
// input 輸入
removeAllSpaceString("Hello World")
removeAllSpaceString("你好     美麗的     世界")

// output 輸出
"HelloWorld"
"你好美麗的世界"
```


### 題目五：字串陣列互換

``` =JavaScript
// input 輸入
stringArraySwitcher(['A', 'B', 'C'])
stringArraySwitcher('1,2,3')

// output 輸出
A,B,C
[1,2,3]
```



### 題目六：字串切割

``` =JavaScript
// input 輸入
getArea("高雄市前鎮區一心二路33號");
getArea("高雄市新興區新興路66號");

// output 輸出
"前鎮區"
"新興區"
```

### 題目七：字串黏合
``` =JavaScript
// input 輸入
concatString("我今天想來點", "六角冰咖啡")

// output 輸出
"我今天想來點六角冰咖啡"
```

### 題目八：顯示字串
請嘗試修改以下代碼，使其可正確運行 (留意單、雙引號)。
關鍵字：單引號、雙引號、反引號、樣板字串。
``` =JavaScript
// To be edit 需修改代碼
console.log("'字串'是 JavaScript 中一種基礎且重要的"型別"，必須好好學習。")

// output 輸出
'字串'是 JavaScript 中一種基礎且重要的"型別"，必須好好學習。

```

### 題目九：擷取字串內容
創造一個函式用於擷取輸入字串的指定索引字元，如找不到，回傳 false 。
``` =JavaScript
// input 輸入
const input = "Hello"
getCharacter(input, 1)
getCharacter(input, 3)
getCharacter(input, 10)

// output 輸出
"H"
"l"
false
```



### 題目十：反轉字串
創造一個函式用於反轉字串內文字的順序。
``` =JavaScript
// input 輸入
stringReverser("hello")

// output 輸出
olleh
```







## 回報流程

1. 將答案貼在 Codepen 並複製 Codepen 連結貼至「回報區」回報
（也可以將答案直接貼至「回報區」）

![](https://i.imgur.com/vftL5i0.png)

<!-- 解答：  -->


## 作業提交等級

* LV1：解出 10 題，並提交 Codepen
* LV2：設計一個 hackmd，嘗試自己設計 10 題
* LV3：嘗試去做其他學生寫的題目，並 tag 學員回報給他，感謝他的命題，讓自己觀念更好

回報區
---

|         Discord         | LV  |                                                             CodePen / 答案                                                             |
|:-----------------------:|:---:|:--------------------------------------------------------------------------------------------------------------------------------------:|
| Iris Huang#6727（範例） | LV1 |                                           [CodePen](https://codepen.io/ythuang/pen/GRxejgE)                                            |
|   Rr #2215               |  LV1   |        [Codepen](https://codepen.io/rufangcheng/pen/jOxXXQG)                                                                                                                                |
|       嗶嗶羊#8042       | LV1 |                            [CodePen](https://codepen.io/mazizlte-the-typescripter/pen/OJZaMOp?editors=0011)                            |
|        Rice#8043        | LV1 |                                    [CodePen](https://codepen.io/riecball/pen/QWrQzop?editors=0011)                                     |
|      CloThEs#8043       | LV1 |                                           [CodePen](https://codepen.io/CloThEsZ/pen/abGQvQK)                                           |
|         VT#0895         | LV1 |                                            [CodePen](https://codepen.io/vt197/pen/gOzQaNp)                                             |
|        Ohno#1144        | LV1 |                                    [Codepen](https://codepen.io/mmaa7850/pen/OJZaMPN?editors=1111)                                     |
|       azami#5986        | LV1 |                                            [CodePen](https://codepen.io/azami/pen/oNdQbPX)                                             |
|      Amberhh#2454       | LV1 |                                     [Codepen](https://codepen.io/Amberhh/pen/PoexZgK?editors=0011)                                     |
|       cotton#7163       | LV1 |                                     [Codepen](https://codepen.io/cottonT/pen/JjveGdx?editors=0010)                                     |
|       Cliff#4606        | LV1 |                                          [Codepen](https://codepen.io/Cliff_hex/pen/Rwyqarg)                                           |
|     JustinLiu#9699      | Lv1 |                                   [CodePen](https://codepen.io/justin0227/pen/BaxGjGw?editors=0012)                                    |
|       albee#9121        | LV1 |                                         [Codepen](https://codepen.io/albee-chang/pen/zYjMqZG)                                          |
|     出事了阿伯#9923     | LV1 |                                   [Codepen](https://codepen.io/BradpittLai/pen/KKRrdJW?editors=1011)                                   |
|       JackC#0411        | LV1 |                                           [Codepen](https://codepen.io/key0329/pen/NWMExpg)                                            |
|       Kevin#6131        | LV1 |                              [Codepen](https://codepen.io/xlqjezvc-the-encoder/pen/JjveKPy?editors=1011)                               |
|      hannahTW#2224      | LV3 |     [Codepen](https://codepen.io/hangineer/pen/GRdwobE?editors=1111)+[HackMD](https://hackmd.io/@XuLchNweTiC4s2NZlAlQDw/Sk5ZUEZ7i)     |
|        圈圈#4060        | LV2 | [Codepen](https://codepen.io/wjejfczn-the-bold/pen/abGQZZL?editors=1111)/[HackMD](https://hackmd.io/@j6ccRYgTTEiVcfMfmAELcw/HJAD1SZmo) |
|     jackson204#6363     | LV1 |                                          [Codepen](https://codepen.io/jackson204/pen/mdLQEEa)                                          |
|        無名#6427        | LV1 |                                     [CodePen](https://codepen.io/Nomoney/pen/gOzQMzV?editors=0011)                                     |
|         YC#2522         | LV1 |                                             [CodePen](https://codepen.io/YCLu/pen/YzLRqZQ)                                             |
|     0xWilliam #8796     | LV1 |                                  [CodePen](https://codepen.io/0xWilliam0322/pen/qBYQNRo?editors=0010)                                  |
|        Fan#3405         | LV1 |                                            [CodePen](https://codepen.io/Fan123/pen/zYjMKqJ)                                            |
|      AuroraC#6539       | LV1 |                                     [codepen](https://codepen.io/AuroraC/pen/ZEompqm?editors=0010)                                     |
|       心幻羽#0056       | LV1 |                                   [CodePen](https://codepen.io/linglingsyu/pen/xxjQVor?editors=1111)                                   |
|        威0#6919         | LV1 |                                   [Codepen](https://codepen.io/n0918679182/pen/rNvQMYQ?editors=0012)                                   |
|        yumy#1940        | LV1 |                                          [Codepen](https://codepen.io/yumy_yamg/pen/zYjMorY)                                           |
|    jacky010080#0880     | Lv1 |                                  [CodePen](https://codepen.io/Yen-Jung-Chen/pen/gOzQwaa?editors=0011)                                  |
|     suihsilan#9485      | Lv1 |                                    [CodePen](https://codepen.io/suihsilan/pen/PoexGxm?editors=0010)                                    |
|        Ayre#0016        | Lv1 |                                   [Codepen](https://codepen.io/yichunlin09/pen/jOxQqbQ?editors=0010)                                   |
|      mandylai#4055      | Lv1 |                                         [Codepen](https://codepen.io/mandy-lai-2/pen/wvjQzRP)                                          |
|        yoyo#1003        | Lv1 |                                  [Codepen](https://codepen.io/crpbugqy-the-typescripter/pen/JjveRNV)                                   |
|       yawun#0042        | Lv1 |                                          [CodePen](https://codepen.io/monicalin/pen/oNdQLrV)                                           |
|      RyanTsai#8906      | Lv1 |                                           [CodePen](https://codepen.io/linlaose/pen/NWMEdGQ)                                           |
|     xherobruce#6825     | Lv1 |                                         [Codepen](https://codepen.io/winwinbruce/pen/qBYQmYR)                                          |
|       SASIMI#5099       | Lv1 |                                         [Codepen](https://codepen.io/sashimi1327/pen/WNJYEzX)                                          |
|       黃士桓#7654       | Lv1 |                                        [codePen](https://codepen.io/shr-huan-huang/pen/BaxGZjE)                                        |
|     Sentiments#4883     | lv1 |                                   [codepen](https://codepen.io/Sentiments/pen/XWqyzMR?editors=0010)                                    |
|        薯餅#3581        | lv1 |                                        [codepen](https://codepen.io/ColdingPoTaTo/pen/ZEomvza)                                         |
|       hungya#0773       | lv1 |                                    [codepen](https://codepen.io/hungya777/pen/RwyqZjr?editors=0011)                                    |
|        Vera#5592        | LV1 |                                            [CodePen](https://codepen.io/skvera/pen/rNvQYNM)                                            |
|        Kimi#9564        | LV1 |                                           [CodePen](https://codepen.io/kimihu91/pen/RwyqqGY)                                           |
|        予予#9627        | LV1 |                                    [CodePen](https://codepen.io/kiqzcraa/pen/abGQQOJ?editors=1011)                                     |
|     KatyChiang#1554     | LV1 |                                     [CodePen](https://codepen.io/Kai0819/pen/eYrQQOJ?editors=0011)                                     |
|     peter.chen#1932     | LV1 |                                          [CodePen](https://codepen.io/JIAN-RONG/pen/poVQqwd)                                           |
|       Greta#0837        | LV1 |                                           [CodePen](https://codepen.io/gretali/pen/NWMEeJw)                                            |
|     hsiung阿熊#4079     | LV1 |                                          [CodePen](https://codepen.io/hsiungchi/pen/NWMEebd)                                           |
|        柔柔#1716        | LV1 |                                     [CodePen](https://codepen.io/rouchen/pen/PoexVvd?editors=1112)                                     |
|       Hazel.#6020       | LV1 |                                   [CodePen](https://codepen.io/Hazelhsieh/pen/abGQmQe?editors=1010)                                    |
|        威爾#1694        | LV1 |                                           [CodePen](https://codepen.io/WILL_Wu/pen/MWGzZEV)                                            |
|      kenki100#0068      | LV1 |                                            [codepen](https://codepen.io/ken100/pen/abGQQZw)                                            |
|       肉桂卷#0625       | LV1 |                                     [codepen](https://codepen.io/ginnlee/pen/OJZagoJ?editors=0011)                                     |
|        Rena#6249        | LV1 |                                   [codepen](https://codepen.io/aureate0116/pen/dyeQLVx?editors=1011)                                   |
|     LHchien33#6232      | LV1 |                                    [codepen](https://codepen.io/lin_chien/pen/jOxQXVw?editors=0011)                                    |
|    William Lai#0196     | LV1 |                                          [codepen](https://codepen.io/lai-weihan/pen/ExLOMjZ)                                          |
|      我是泇吟#5189      | LV1 |                                           [CodePen](https://codepen.io/kljuqbxs/pen/KKRrLar)                                           |
|       Winnie#1306       | LV1 |                                 [CodePen](https://codepen.io/WinnieWuWinnie/pen/RwyqaOJ?editors=0012)                                  |
|       法希娜#3206       | LV1 |                              [CodePen](https://codepen.io/yiiserpf-the-encoder/pen/BaxGeBw?editors=0112)                               |
|       Baozi#2042        | LV1 |                                          [CodePen](https://codepen.io/lillianyu/pen/OJZaGOR)                                           |
|      banazita#5143      | LV1 |                                    [CodePen](https://codepen.io/banazita/pen/OJZazbX?editors=1111)                                     |
|        萱仔#0781        | LV2 |           [CodePen](https://codepen.io/ting-hsuan/pen/YzLRwaw)/[HackMD](https://hackmd.io/@_wbHICMwRFSwudgB4jkbLw/BkycPeXmi)           |
|         VK#6657         | LV1 |                                             [CodePen](https://codepen.io/VKCS/pen/mdLaJpB)                                             |
|        Data#9297        | LV1 |                                          [CodePen](https://codepen.io/kirakira72/pen/NWMEXza)                                          |
|        芮綺#5224        | LV1 |                                     [CodePen](https://codepen.io/zhan70/pen/YzLRwyK?editors=0011)                                      |
|     Ron Liang#7277      | LV1 |                                            [CodePen](https://codepen.io/ron-go/pen/dyewMyY)                                            |
|        RJRS#9430        | LV1 |                                             [CodePen](https://codepen.io/RJRS/pen/bGMOdmm)                                             |
|      Judy ☻ #7874       | LV1 |                                    [CodePen](https://codepen.io/hsiaohan/pen/WNJYYJQ?editors=0011)                                     |
|        yen #5757        | LV1 |                                  [CodePen](https://codepen.io/TZU-HUANG-YEN/pen/zYjMWyR?editors=1111)                                  |
|      Joy1712#4670       | LV1 |                                     [CodePen](https://codepen.io/Joy1712/pen/YzLRwWz?editors=0011)                                     |
|       Eileen#6454       | LV1 |                                          [CodePen](https://codepen.io/Eileen-io/pen/rNvQRYy)                                           |
|        Yiru#0236        | Lv1 |                                     [Codepen](https://codepen.io/yiru94/pen/MWGzRjO?editors=0012)                                      |
|       Iris_#8462        | Lv1 |                                    [Codepen](https://codepen.io/irissamy/pen/VwxVVYQ?editors=1111)                                     |
|        m_m#5493         | Lv1 |                                          [Codepen](https://codepen.io/minnn7716/pen/XWqoVmV)                                           |
|     Yuna Huang#2692     | Lv1 |                                    [Codepen](https://codepen.io/Yuna1002/pen/dyewZZm?editors=0011) [CodePen](https://codepen.io/morefoodq/pen/KKRbOWa)|
|k.sin#3115|LV1|[CodePen](https://codepen.io/sin588/pen/RwyqgLv?editors=0011)|
|蓁心#6229|LV1|[CodePen](https://codepen.io/tlorfrnl-the-typescripter/pen/XWqydLN)|
|王懷英#7271|LV1|[CodePen](https://codepen.io/huaiying/pen/PoeVJZb)|
|Hironaka#7367||[CodePen](https://codepen.io/Hironaka0815/pen/qBYgVyX?editors=0011)|
|ssozr#4680||[CodePen](https://codepen.io/ssozr/pen/NWMeXrr?editors=0010)|
|艸良#2846|LV1|[CodePen](https://codepen.io/momoninainai/pen/KKRrMKw)|
|三隻小貓#1905|LV1|[Codepen](https://codepen.io/bagelover/pen/BaxMdxj?editors=0011)|
|Chian#1564|LV1|[codepen](https://codepen.io/chian-yang/pen/poVYPYO?editors=0011)|
|Chloe#5422|LV1|[codepen](https://codepen.io/Ironchloe/pen/QWroPOb?editors=0010)|
|Jhen#4563|LV1|[codepen](https://codepen.io/su-jhen/pen/oNdVVQW?editors=0012)|
|H.L.C#2152|LV1|[codepen](https://codepen.io/hsin-liang/pen/PoeLBBa)|
|kuku#3118|LV1|[Codepen](https://codepen.io/mengting-ku/pen/WNJWNvz?editors=1011)
|Curtis#4780| LV1| [CodePen](https://codepen.io/curtislin/pen/oNdOBzb?editors=0010)|
|Irene#0086|Lv1|[codepen](https://codepen.io/HalfPlannedJourney/pen/NWMmggM)|
|LQQ#4187|Lv1|[codepen](https://codepen.io/morefoodq/pen/KKRbOWa)|
| 小白#2406 | LV1 | [CodePen](https://codepen.io/gracewhite/pen/VwxVaaP) |
|sophiee#7015|LV1|[Codepen](https://codepen.io/sophiee2727/pen/QWrPmXo)|
|安o#2448|LV1|[Codepen](https://codepen.io/JzhenAn/pen/poVXeKM)|
|MotoRin|LV1|[Codepen](https://codepen.io/casslam/pen/abGevxr)|
|軟綿綿 (๑•ᴗ•๑) ♡#3627|LV1|[CodePen](https://codepen.io/Connie-Chien/pen/rNvXOyv)|
|Paul#7426|LV1|[CodePen](https://codepen.io/paul-1997/pen/xxzKdyL?editors=0011)|
|Clara#1275|LV1|[CodePen](https://codepen.io/bsupixqu/pen/rNKBPre?editors=1012)|
|charlottelee849#0366|LV1|[CodePen](https://codepen.io/charlotte-lee/pen/KKewQjL?editors=1111)|
|Ryan Chiang#6649|LV1|[Codepen](https://codepen.io/ryanchiang/pen/zYazojX?editors=0012)|
|Tami#6742|LV1|[CodePen](https://codepen.io/wqsdqbjn-the-vuer/pen/dyKgbgx)|