Search Unity

TextMesh Pro \r vs \n

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by andyz, Jun 14, 2019.

  1. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    1,128
    Definition of '\r' varies between newline (like \n) or just carriage return I think, but I thought they were treated much the same since why would you want to go back to the start of a line without doing a newline - I think mac used to just use \r and no \n (though windows \r\n)?

    Anyway I noticed TextMesh Pro does treat \r [on its own] in a string as just go back to the line start rather than doing a newline so... is this the best thing, rather than doing same as \n or \r\n?
    Some text sources use \r alone without \n so you then have to do a string replace before using with a TextMesh Pro text field.
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,189
    Carriage return - char(13) - \r provides specific functionality which is to return the carriage / pen to the start position of the given line whereas Linefeed - char(10) - \n inserts a new line and also returns the carriage / pen to the start of the line.

    Since there are many TMP users using Carriage return for its true design purpose, it cannot be combined or changed to become a linefeed since the would break their projects and also be incorrect in terms of handling.

    The best way to handle this is to make sure you parse the incoming strings / text to validate these control characters. Most of the time, this parsing is also needed when text is coming from xml, html, csv, etc. files which also tend to escape these control characters.
     
  3. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    1,128
    I'm ok with that, but curious to know if there is any use case for 'carriage/pen returning to start pos' only!
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,189
    When trying to create / simulate any type of console / computer terminal or over write on top of existing text. I guess the same could be done by setting the <line-height=0> but I know some users are using it and that is what this control character was designed to do so I left it as is.