Set string with new line charater

Discussion in 'Spigot Plugin Development' started by Pannkaka, Apr 22, 2017.

  1. Hello!

    Consider the following string:
    Code (Text):
    "%prefix% &cWrong usage of command!\n Correct usage: %correct_usage%"
    If i save that to a YAML file would it be vsaved like that and i don't want it to be saved like that.
    [​IMG]

    How would i do in order to just save the plain string instead of that?
     
  2. WAS

    WAS

    Perhaps StringEscapeUtils#escapeJava() would help you?

    Alternately str#replace("\\n", "\\\\n") and back with str#replace("\\\\n", "\\n")
     
  3. Mas

    Mas

    Is there any reason why you don't want it saved like that?
    I personally think it's a much nicer format to read when editing multiple lines like that then, rather than having to put \n everywhere.

    If you really want it differently, tell your users to use another format for new lines and then replace them at runtime.
     
  4. WAS

    WAS

    On a parsing level, it does matter. Maybe not all too noticeable, but when you begin piling up code with that sort of logic...