Return symbol: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
| Line 59: | Line 59: | ||
<td>特例: 無內容的空檔案</td> | <td>特例: 無內容的空檔案</td> | ||
<td>empty</td> | <td>empty</td> | ||
</tr> | |||
</table> | |||
== 不同換行符號 在不同作業系統的編輯器看到的狀況 == | |||
<table border="1" class="wikitable" > | |||
<tr> | |||
<th>檔案內容</th> | |||
<th>Windows 10 內建「記事本」</th> | |||
<th>Windows 10 免費編輯器 [https://notepad-plus-plus.org/zh/ Notepad++] v. 7.5.9</th> | |||
<th>Mac 內建「[https://support.apple.com/zh-tw/guide/textedit/welcome/mac 文字編輯.app]」</th> | |||
<th>Mac 編輯器 [https://www.sublimetext.com/ Sublime Text] v. 3.2</th> | |||
</tr> | |||
<tr> | |||
<td>換行符號是 {{kbd | key=<nowiki>CRLF</nowiki>}} = {{kbd | key=<nowiki>\r\n</nowiki>}}</td> | |||
<td>ok</td> | |||
<td>ok</td> | |||
<td>ok</td> | |||
<td>ok</td> | |||
</tr> | |||
<tr> | |||
<td>換行符號是 {{kbd | key=<nowiki>LF</nowiki>}} = {{kbd | key=<nowiki>\n</nowiki>}}</td> | |||
<td>{{exclaim}} 預期不同行的內容擠在一起</td> | |||
<td>ok</td> | |||
<td>ok</td> | |||
<td>ok</td> | |||
</tr> | |||
<tr> | |||
<td>換行符號是 {{kbd | key=<nowiki>CR</nowiki>}} = {{kbd | key=<nowiki>\r</nowiki>}}</td> | |||
<td>{{exclaim}} 預期不同行的內容擠在一起</td> | |||
<td>ok</td> | |||
<td>ok</td> | |||
<td>ok</td> | |||
</tr> | </tr> | ||
Revision as of 14:49, 15 March 2019
換行符號 (Return symbol, line terminators, line endings, newline, end of line (EOL), line feed or line break)
- On Win
: CRLF = \r\n - On Unix, Linux
& recent versions of macOS
: LF = \n - On classic versions of macOS
[1][2] e.g. Mac OS 9: CR = \r
如何看到換行符號
查看每一行使用的換行符號
- Notepad++ On Win
選單 → 檢視 → 特殊字元 → 顯示行尾字元 (EOL) - RawLineEdit for Sublime text
- 換行符號是 CRLF = \r\n 顯示的是 <0x0d>¬
- 換行符號是 LF = \n 顯示的是 ¬ 象形符號 (glyph)
- 換行符號是 CR = \r 顯示的是 <0x0d>
- BASH cat command e.g. cat -e <filename>
- 換行符號是 CRLF = \r\n 顯示的是 ^M$
- 換行符號是 LF = \n 顯示的是 $
- 換行符號是 CR = \r 顯示的是 ^M
查看檔案使用的換行符號
- atom/line-ending-selector: Switch between Unix and Window style line endings. for Atom on Win
, macOS
& Linux
- file (command): file filename.txt on Linux
, macOS
[3] & Cygwin on Win
| 檔案內容 | File command 偵測結果 |
|---|---|
| 換行符號是 CRLF = \r\n | UTF-8 Unicode text, with CRLF line terminators |
| 換行符號是 LF = \n | UTF-8 Unicode text |
| 換行符號是 CR = \r | UTF-8 Unicode text, with CR line terminators |
| 特例: 換行符號夾雜 \r\n 和 \r | UTF-8 Unicode text, with CRLF, CR line terminators |
| 特例: 換行符號夾雜 \r\n 和 \n | UTF-8 Unicode text, with CRLF, LF line terminators |
| 特例: 換行符號夾雜 \n 和 \r | UTF-8 Unicode text, with CR, LF line terminators |
| 特例: 無內容的空檔案 | empty |
不同換行符號 在不同作業系統的編輯器看到的狀況
| 檔案內容 | Windows 10 內建「記事本」 | Windows 10 免費編輯器 Notepad++ v. 7.5.9 | Mac 內建「文字編輯.app」 | Mac 編輯器 Sublime Text v. 3.2 |
|---|---|---|---|---|
| 換行符號是 CRLF = \r\n | ok | ok | ok | ok |
| 換行符號是 LF = \n | ok | ok | ok | |
| 換行符號是 CR = \r | ok | ok | ok |
如何取代換行符號
- 支援 Regular expression 的文字編輯軟體,例: 將Email清單,轉成Email軟體可以使用的寄信名單 (取代換行符號為逗號)
- MySQL: SELECT REPLACE(REPLACE(REPLACE(`column`,'\r\n',''),'\n',''),'\r','') [4]
- Excel: 3 ways to remove carriage returns in Excel: formulas, VBA macro, find&replace dialog [Last visited: 2018-05-24]
Related articles
- Carriage return - Wikipedia
- 換行 - 维基百科,自由的百科全书
- 回車鍵 - 維基百科,自由的百科全書
- 陳雲濤的部落格: 筆記 CRLF跟LF之區別 --- 隱形的 bug:「CRLF才是真正的打字機運作方式,你可以想像:打字機打到最右邊,要先return到最左邊之後,再往下一行,所以是CRLF ... ...」
- Differences in end of line characters Mac, Windows, and Linux
- php - How to remove carriage returns from output of string? - Stack Overflow
References