/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();
               
            }
        }

你可能感兴趣的:(/r, /n 和 /r/n的来历与区别)