ข้อความ
CRLF ↔ LF Converter
แปลงอักขระขึ้นบรรทัดใหม่ระหว่าง Windows (CRLF), Unix/macOS (LF) และ Mac รุ่นคลาสสิก (CR) พร้อมตรวจจับรูปแบบผสม
เบราว์เซอร์จะแปลงข้อความที่วางในช่องนี้เป็น LF โดยอัตโนมัติ จึงไม่สามารถตรวจจับ CRLF/CR ดั้งเดิมได้ที่นี่ — หากต้องการวิเคราะห์หรือแปลงไฟล์ที่มี CRLF/CR จริง ให้ใช้การอัปโหลดไฟล์ด้านบน
Windows, Unix/macOS, and the old classic Mac historically use different characters to mark the end of a line — CRLF, LF, and CR respectively. Mixing these styles in one file often causes odd artifacts in diffs or editors. This tool converts line endings to one style and detects mixed ones.
How to use it
- Paste text and the tool automatically detects the current line-ending style, including a mixed one.
- Pick a target format (CRLF, LF, or CR) and the conversion happens instantly.
- If several styles are found in the same file, that's flagged with a separate warning.
Common uses
- Fixing a file where git diff shows every line as changed because of differing line endings, even though the content itself didn't actually change.
- Converting a text file to the format a specific system or script expects (a Unix script, for instance, expects LF).
- Debugging why a file opened in a Windows editor shows the entire text on one line (a sign of plain LF with no CR).
Things to keep in mind
Git can automate this conversion itself through core.autocrlf or .gitattributes — often more convenient than converting files in a repository by hand.
Mixed line endings in one file aren't always visible at a glance, but they can break parsers or scripts that expect one specific style.
บทความเกี่ยวกับเครื่องมือนี้: CRLF กับ LF: ทำไมการขึ้นบรรทัดใหม่ยังคงสร้างปัญหา
คำถามที่พบบ่อย
ทำไมอักขระขึ้นบรรทัดใหม่จึงแตกต่างกันตามระบบ?
Windows ใช้ CRLF (\r\n), Unix และ macOS ใช้เพียง LF (\n) ส่วน Mac รุ่นเก่าใช้เพียง CR (\r) — ธรรมเนียมทางประวัติศาสตร์ที่แตกต่างกันนี้ทำให้เกิดความไม่สอดคล้องเมื่อไฟล์ย้ายระหว่างระบบ
ทำไมฉันต้องอัปโหลดไฟล์แทนการวางข้อความ?
เบราว์เซอร์จะปรับข้อความใดๆ ที่วางลงในช่องกรอกข้อมูลให้เป็น LF โดยอัตโนมัติ ดังนั้นอักขระ CRLF หรือ CR ดั้งเดิมจริงจะตรวจไม่พบหลังจากวางแล้ว — มีเพียงการอัปโหลดไฟล์โดยตรงเท่านั้นที่รักษาอักขระขึ้นบรรทัดใหม่จริงไว้สำหรับการวิเคราะห์หรือแปลง
ปัญหาแบบนี้สำคัญจริงๆ เมื่อไหร่?
สำคัญที่สุดกับ git (diff ที่รกเนื่องจากอักขระขึ้นบรรทัดใหม่), สคริปต์ shell ที่ล้มเหลวเพราะ CRLF ที่หลงเหลือ และไฟล์ที่แลกเปลี่ยนระหว่างระบบ Windows กับ Unix/macOS; ไฟล์ที่อัปโหลดจะถูกประมวลผลในเบราว์เซอร์เท่านั้น ไม่เคยส่งไปยังเซิร์ฟเวอร์
ต้องทำอย่างไรถ้าไฟล์มี CRLF และ LF ปนกัน?
ไฟล์ที่ถูกแก้ไขในโปรแกรมแก้ไขหลายตัวหรือหลายระบบปฏิบัติการอาจมีทั้งสองรูปแบบปนกัน การแปลงต้องใช้กับทั้งไฟล์ ไม่ใช่แค่บรรทัดที่ดูน่าสงสัย มิฉะนั้นอักขระขึ้นบรรทัดที่มีปัญหาบางส่วนจะยังไม่ถูกตรวจพบ
สามารถทำให้การแปลงเป็นอัตโนมัติผ่าน git ได้หรือไม่?
ได้ การตั้งค่า core.autocrlf ใน git จะแปลงอักขระขึ้นบรรทัดโดยอัตโนมัติเมื่อ checkout และ commit ส่วน .gitattributes ช่วยให้กำหนดรูปแบบอักขระขึ้นบรรทัดสำหรับไฟล์แต่ละประเภทในที่เก็บได้อย่างชัดเจน