Remark : Windows 와 Linux 에서 줄바꿈 newline 표시 방법
Linux 로 만들어진 웹서비스인 장문의 리턴값은 windows 줄바꿈(CRLF) Text 와 다른게 LF(line Feed) 만 존재
줄바꿈 문자
- 윈도우는 CRLF(\r\n)
- 리눅스는 LF (\n)
CR LF 정의
- CR : Carriage Return (\r)
- LF : Line Feed (\n)
“\r\n”, “\r”, “\n” 각각 문자 자리수는 어떻게 되나 ?
,
\r\n
, 그리고 \r\n
은 텍스트에서 줄바꿈을 나타내는 문자(또는 문자 조합)입니다. 각각의 문자(또는 문자 조합)의 자리수는 다음과 같습니다:
\n
(LF, Line Feed): 유닉스 및 유닉스 계열 시스템(리눅스, macOS 등)에서 사용되는 줄바꿈 문자로, 1자리를 차지합니다.\r
(CR, Carriage Return): 고전 매킨토시 시스템에서 사용되는 줄바꿈 문자로, 1자리를 차지합니다.\r\n
(CRLF, Carriage Return + Line Feed): 윈도우 시스템에서 사용되는 줄바꿈 문자 조합으로, 2자리를 차지합니다 (\r
과\n
의 결합).
c# (Linux Text to Windows)
1 2 3 4 |
//replace sText \n => \r\n sText = sText.Replace("\n", "\r\n"); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
using System; using System.Text.RegularExpressions; class Program { static void Main() { string text = @" 11. BLACKOUT DATES NO BLACKOUT DATES APPLY. 12. SURCHARGES NO SURCHARGE REQUIREMENTS APPLY. 13. ACCOMPANIED TRAVEL ACCOMPANIED TRAVEL NOT REQUIRED. 14. TRAVEL RESTRICTIONS VALID FOR TRAVEL COMMENCING ON/AFTER 01APR24 AND ON/ BEFORE 31MAR25. 15. SALES RESTRICTIONS TICKETS MUST BE ISSUED ON/AFTER 30JAN24 AND ON/BEFORE 31MAR25. "; string indentedText = IndentText(text); Console.WriteLine(indentedText); } static string IndentText(string text) { var lines = text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); var pattern = @"^\d{2}\."; for (int i = 0; i < lines.Length; i++) { if (!Regex.IsMatch(lines[i], pattern)) { lines[i] = " " + lines[i]; } } return String.Join(Environment.NewLine, lines); } } |