蛋疼的回车换行符

\r = 回车 = carriage return = CR = 13

\n = 换行 =  line feed = LF = 10

 

在Windows操作系统中,回车=将光标移动到一行的开始,换行=将光标移动到下一行。

在Linux系统中,换行=将光标移动到下一行的开始。

在Mac中,回车=将光标移动到下一行。

 

在Java的BufferedReader中,readLine方法其实是将\r,\n以及\r\n统统认为是一行的分隔符的:

    /**
     * Reads a line of text.  A line is considered to be terminated by any one
     * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
     * followed immediately by a linefeed.
     *
     * @return     A String containing the contents of the line, not including
     *             any line-termination characters, or null if the end of the
     *             stream has been reached
     *
     * @exception  IOException  If an I/O error occurs
     */
    public String readLine() throws IOException {
        return readLine(false);
    }

 

而readLine的另一个重载,则允许指定是否忽略LF(回车)符号。

    /**
     * Reads a line of text.  A line is considered to be terminated by any one
     * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
     * followed immediately by a linefeed.
     *
     * @param      ignoreLF  If true, the next '\n' will be skipped
     *
     * @return     A String containing the contents of the line, not including
     *             any line-termination characters, or null if the end of the
     *             stream has been reached
     * 
     * @see        java.io.LineNumberReader#readLine()
     *
     * @exception  IOException  If an I/O error occurs
     */
    String readLine(boolean ignoreLF) throws IOException {

 

不同的编辑器对回车换行符的支持也不同。

其中Notepad++是都支持,跟Java默认是一样的。

np

在VIM中,恪守了Linux里的规则,回车被显示成一个^M,换行则是换行。

vim

 

这不是纯蛋疼嘛。。。。。。。。。。。。。。。。。。。统一一下不就得了嘛。

posted @ 2011-07-01 18:10  深夜两点  阅读(2632)  评论(3编辑  收藏  举报