Solved Replacing the Line Feed character with \n?

Discussion in 'Plugin Development' started by ColonelHedgehog, Dec 15, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ColonelHedgehog

    This may be more of a Java question.

    I've been using GSON to access strings lately. The problem, however, is when I get a string and turn it into an item lore, instead of having the default \n character, it gives me the LF (\uoooA). This is a problem because I can't seem to get rid of it, and it doesn't even give a line break.

    Example: [​IMG]

    Is there a way to replace the [LF] character with the \n character? I've tried replace/replaceAll with the \uoooA character, but it didn't work.
     
  2. Offline

    tcvs

    @ColonelHedgehog Your picture does not load for me...

    Edit: Now it is :p

    Edit2: You need to check whether that string contains that and if it does then replace it with a line break.
     
  3. Offline

    Rocoty

    @ColonelHedgehog I think you're confused. \n IS line feed. Have you tried replacing \n with \r\n? (Carriage Return + Line Feed)
     
  4. Offline

    ColonelHedgehog

    @tcvs: Uh, that's what I'm trying to do.

    It is? Oops.

    Yes, I have, and still no luck.

    Code:Java
    1.  
    2. strs.add("ยง9" + l.getName().replaceAll("\n", "\r\n"));


    I tried replacing \n as well as the Unicode version.
     
  5. Offline

    Rocoty

    @ColonelHedgehog Hold on...you're stuffing this into ItemStack lore? In that case you should add each new line as a new element in the list.

    EDIT: Just tested this. It's almost certainly the root to your problems.
     
    Last edited: Dec 15, 2014
  6. Offline

    ColonelHedgehog

    I was worried that would be the case.

    Now to determine how I'd go about detecting where to put the new lines. ;_;
     
  7. Offline

    Rocoty

  8. Offline

    ColonelHedgehog

    Yeah, I'm going to try that as soon as I fix an Async problem. I'll let you know if that works.
     
  9. Offline

    Lolmewn

    Try using replace() instead of replaceAll() - ReplaceAll uses Regex while replace doesn't.
     
  10. Offline

    Rocoty

    @Lolmewn In this particular case that would make no difference, as \n is legit regex for line feed. But I can see what you're getting at, and .replace() is the obvious choice here. (Apart from the fact that the problem was related to the way ItemStack lore handles newline characters, so replacing wouldn't work anyway.)
     
    Lolmewn likes this.
  11. Offline

    ColonelHedgehog

    Already tried that, but thanks.

    Still trying to fix the Async problem. ._.
     
  12. Offline

    mythbusterma

  13. Offline

    ColonelHedgehog

    Oh, well I figured it out, but since my plugin accesses GSON documents from other websites, then translates the text into lores. I wanted part of it to operate as Async (but obviously not the Inventory editing and such), while still being able to fetch the main-thread values. I got this sorted.

    Also, thanks for the help. It's no longer showing the LF character. :)
     
Thread Status:
Not open for further replies.

Share This Page