/r, /n 和 /r/n的來歷與區別

'/r'是回車,'/n'是換行,前者使光標到行首,後者使光標下移一格。通常用的Enter是兩個加起來。下面轉一篇文章。



回車和換行
今天,我總算搞清楚“回車”(carriage return)和“換行”(line feed)這兩個概念的來歷和區別了。
在計算機還沒有出現之前,有一種叫做電傳打字機(Teletype Model 33)的玩意,每秒鐘可以打10個字符。但是它有一個問題,就是打完一行換行的時候,要用去0.2秒,正好可以打兩個字符。要是在這0.2秒裏面,又有新的字符傳過來,那麼這個字符將丟失。

於是,研製人員想了個辦法解決這個問題,就是在每行後面加兩個表示結束的字符。一個叫做“回車”,告訴打字機把打印頭定位在左邊界;另一個叫做“換行”,告訴打字機把紙向下移一行。

這就是“換行”和“回車”的來歷,從它們的英語名字上也可以看出一二。

後來,計算機發明瞭,這兩個概念也就被般到了計算機上。那時,存儲器很貴,一些科學家認爲在每行結尾加兩個字符太浪費了,加一個就可以。於是,就出現了分歧。

Unix系統裏,每行結尾只有“<換行>”,即“/n”;Windows系統裏面,每行結尾是“<換行><回車>”,即“/n/r”;Mac系統裏,每行結尾是“<回車>”。一個直接後果是,Unix/Mac系統下的文件在Windows裏打開的話,所有文字會變成一行;而Windows裏的文件在Unix/Mac下打開的話,在每行的結尾可能會多出一個^M符號。

c語言編程時(windows系統)/r 就是return 回到 本行 行首 這就會把這一行以前的輸出 覆蓋掉
如:
int main() {
cout << "hahaha" << "/r" << "xixi" ;
}
最後只顯示 xixi 而 hahaha 被覆蓋了
/n 是回車+換行 把光標 先移到 行首 然後換到下一行 也就是 下一行的行首拉
int main() {
cout << "hahaha" << "/n" << "xixi" ;
}
則 顯示
hahaha
xixi
舉例:
SpecFlow中讀取SQL 語句
| SQL script                                                                                                          |
| DECLARE @currentServiceRequestID INT                                                                                |
| SET @currentServiceRequestID = -1                                                                                   |
| WHILE 1=1                                                                                                           |
| BEGIN                                                                                                               |
| DECLARE @tempID INT                                                                                                 |
| SELECT TOP 1 @tempID = ServiceRequestID                                                                             |
| FROM ServiceRequest                                                                                                 |
| WHERE ServiceRequestId > @currentServiceRequestID                                                                   |
| ORDER BY ServiceRequestId                                                                                           |
| IF @@ROWCOUNT = 0 BREAK                                                                                             |
| SELECT @currentServiceRequestID = @tempID                                                                           |
| -- Get uploaded files count                                                                                         |
| DECLARE @uploadedFilesCount INT                                                                                     |
| SELECT @uploadedFilesCount = COUNT(UploadFileId)                                                                    |
| FROM UploadFiles                                                                                                    |
| WHERE ServiceRequestId = @currentServiceRequestID                                                                   |
| AND ISNULL(DeletedBy, '') = ''                                                                                      |
| -- Update allNotes, questionnaire answers, uploaded files count                                                     |
| IF EXISTS (SELECT ServiceRequestID FROM ServiceRequestStatistics WHERE ServiceRequestID = @currentServiceRequestID) |
| BEGIN                                                                                                               |
| UPDATE ServiceRequestStatistics                                                                                     |
| SET UploadFilesCount = @uploadedFilesCount                                                                          |
| ,AllNotes = dbo.GetAllNotesByServiceRequestID(@currentServiceRequestID)                                             |
| ,AllQuestionnaireAnswers = dbo.GetQuestionnaireAnswersByServiceRequestID(@currentServiceRequestID)                  |
| WHERE ServiceRequestID = @currentServiceRequestID                                                                   |
| END                                                                                                                 |
| ELSE BEGIN                                                                                                          |
| INSERT ServiceRequestStatistics(ServiceRequestID, UploadFilesCount, AllNotes, AllQuestionnaireAnswers)              |
| SELECT @currentServiceRequestID                                                                                     |
| ,@uploadedFilesCount                                                                                                |
| ,dbo.GetAllNotesByServiceRequestID(@currentServiceRequestID)                                                        |
| ,dbo.GetQuestionnaireAnswersByServiceRequestID(@currentServiceRequestID)                                            |
| END                                                                                                                 |
| END                                                                                                                 |
-----------code------------
        public void SyncExistingSRInfoToTableServiceRequestStatistics(Table table)
        {
           
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ShotgunDB"].ConnectionString);
           
            connection.Open();
            using (SqlCommand command = new SqlCommand())
            {
                string strScript = "";
                foreach (TableRow eachrow in table.Rows)
                { strScript= strScript + "/r/n" +eachrow[0]; }
               
                command.CommandType = CommandType.Text;
                command.Connection = connection;
                command.CommandText = strScript;
                command.ExecuteNonQuery();
               
            }
        }
發佈了51 篇原創文章 · 獲贊 10 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章