mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-30 12:05:39 -05:00
2.2 KiB
2.2 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244b6 | 轉義字符 | 1 | https://scrimba.com/c/cvmqRh6 | 17567 | escape-sequences-in-strings |
--description--
引號不是字符串中唯一可以被轉義(escaped)的字符。 轉義字符允許你使用可能無法在字符串中使用的字符。
| 代碼 | 輸出 |
|---|---|
\' | 單引號 |
\" | 雙引號 |
\\ | 反斜槓 |
\n | 換行符 |
\t | 製表符 |
\r | 回車 |
\b | 退格符 |
\f | 換頁符 |
請注意,反斜線本身必須被轉義,才能顯示爲反斜線。
--instructions--
使用轉義字符把下面三行文本賦值給一個變量 myStr。
FirstLine
\SecondLine
ThirdLine
你需要使用轉義字符正確地插入特殊字符。 你也需要確保間距與上面文本一致,並且單詞或轉義字符之間沒有空格。
注意:SecondLine 前面的空白是製表符,而不是空格。
--hints--
myStr 不能包含空格。
assert(!/ /.test(myStr));
myStr 應包含字符串 FirstLine、SecondLine 和 ThirdLine(記得區分大小寫)。
assert(
/FirstLine/.test(myStr) && /SecondLine/.test(myStr) && /ThirdLine/.test(myStr)
);
FirstLine 後面應該是一個換行符 \n。
assert(/FirstLine\n/.test(myStr));
myStr 應該包含一個製表符 \t,它在換行符後面。
assert(/\n\t/.test(myStr));
SecondLine 前面應該是反斜槓 \。
assert(/\\SecondLine/.test(myStr));
SecondLine 和 ThirdLine 之間應該是換行符。
assert(/SecondLine\nThirdLine/.test(myStr));
myStr 應該只包含上面要求的字符。
assert(myStr === 'FirstLine\n\t\\SecondLine\nThirdLine');
--seed--
--seed-contents--
const myStr = ""; // Change this line
--solutions--
const myStr = "FirstLine\n\t\\SecondLine\nThirdLine";