添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

在電腦還沒有出現之前,有一種叫做電傳打字機(Teletype Model 33)的玩意,每秒鐘可以打10個字元。但是它有一個問題,就是打完一行換行的時候,要用去0.2秒,正好可以打兩個字元。要是在這0.2秒裡面,又有新的字元傳過來,那麼這個字元將丟失。於是,研製人員想了個辦法解決這個問題,就是在每行後面加兩個表示結束的字元。一個叫做“斷行符號”,告訴打字機把列印頭定位在左邊界;另一個叫做“換行”,告訴打字機把紙向下移一行。到了GUI時代游標都是自由移動的不再有斷行符號的意義...

所以符合Windows開發標準的文字編輯器Visual Studio才會提醒你當前編輯的文本不符合Windows行尾標準..

1.Windows 中的分行符號"\r\n"

2.Unix/Linux 平台分行符號是 "\n"。

3.MessageBox.Show() 的分行符號為 "\n"

4.Console 的分行符號為 "\n"

分行符號還因平台差異而不同。

解決方案:

1. 為保持平台的通用性,可以用系統預設分行符號 System.Environment.NewLine。

2. 替換所有的非標準分行符號

 1 class Program_Utf8 2    { 3        static void Main(string[] args) 4        { 5            String folderPath = @"E:\檔案夾路徑\"; 6  7            ParseDirectory(folderPath, "*.cs", (filePath) => 8            { 9                string text = "";10                using (StreamReader read = new StreamReader(filePath, Encoding.Default))11                {12                    string oldtext = read.ReadToEnd();13                    text = oldtext;14                    text = text.Replace("\n", "\r\n");15                    text = text.Replace("\r\r\n", "\r\n"); // 防止替換了正常的分行符號      16                    if (oldtext.Length == text.Length)17                    {18                        Console.WriteLine(filePath.Substring(filePath.LastIndexOf("\\") + 1) + " 不需要標準化");19                        return; // 如果沒有變化就退出                  20                    }21                }22                File.WriteAllText(filePath, text, Encoding.UTF8); //utf-8格式儲存,防止亂碼23 24                Console.WriteLine(filePath.Substring(filePath.LastIndexOf("\\") + 1) + " 行尾標準化完成");25            });26 27            Console.ReadKey();28        }29 30        /// <summary>遞迴所有的目錄,根據過濾器找到檔案,並使用委託來統一處理</summary>31        /// <param name="info"></param>32        /// <param name="filter"></param>33        /// <param name="action"></param>34        static void ParseDirectory(string folderPath, string filter, Action<string> action)35        {36            if (string.IsNullOrWhiteSpace(folderPath)37                || folderPath.EndsWith("debug", StringComparison.OrdinalIgnoreCase)38                || folderPath.EndsWith("obj", StringComparison.OrdinalIgnoreCase)39                || folderPath.EndsWith("bin", StringComparison.OrdinalIgnoreCase))40                return;41 42            Console.WriteLine("讀取目錄:" + folderPath);43 44            // 處理檔案45            string[] fileNameArray = Directory.GetFiles(folderPath, filter);46            if (fileNameArray.Length > 0)47            {48                foreach (var filePath in fileNameArray)49                {50                    action(filePath);51                }52            }53            else54            {55                Console.WriteLine("未發現檔案!");56            }57 58            Console.WriteLine("====================================");59 60            //得到子目錄,遞迴處理61            string[] dirs = Directory.GetDirectories(folderPath);62            var iter = dirs.GetEnumerator();63            while (iter.MoveNext())64            {65                string str = (string)(iter.Current);66                ParseDirectory(str, filter, action);67            }68        }69    }
View Code

vs報錯“以下檔案中的行尾不一致,是否將行尾標準化”

本文章原先以中文撰寫並發佈於 aliyun.com,亦設英文版本,僅作資訊用途。本網站不對文章的準確性,完整性或可靠性或其任何翻譯作出任何明示或暗示的陳述或保證。如對該文章有任何疑慮或投訴,請傳送電郵至 [email protected] 並提供相關疑慮或投訴的詳細說明。職員會於 5 個工作天內與您聯絡,一經驗證之後,即會刪除該侵權內容。

相關關鍵詞: asana vs trello vs quickbase vs vs rand axure vs zendesk vs nagios vs hootsuite vs

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: [email protected] 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

Get Started for Free //intl.aliyun.com/pricing //intl.aliyun.com/trust-center //intl.aliyun.com/free-trial/enterprise //intl.aliyun.com/startup //intl.aliyun.com/partner