Solved [Noob] String not splitting right

Discussion in 'Spigot Plugin Development' started by GCNT, Mar 17, 2019 at 1:12 PM.

  1. GCNT

    GCNT Previously lukas.vdgaag

    hey everyone,

    So, this is a pretty noob thing probably, but I still need to know it.
    I've a string that looks like:
    Code (YAML):
    &d&lDELAY \n &7This title is 10 seconds delayed!
    And i need to split the string in two parts using string.split("\\n");
    Which is literally my code...

    But it's not splitting. I've already debugged everthing possible. But it only returns the whole string.

    Code:
    Code (Java):
    String string = "&d&lDELAY \n &7This title is 10 seconds delayed!";
    String[] ss = string.split("\\n");
    console.print(ss[0]);
    console.print(ss[1]);
     
  2. Try this:
    Code (Java):
    String[] ss=string.split("\\\\n");
     
    • Winner Winner x 1
  3. GCNT

    GCNT Previously lukas.vdgaag

    Why so much backslashes?
     
  4. I found the same solution on Stackoverflow when I had this problem.
     
  5. I always do it this way

    Code (Java):

    String str = "your\nsplitstring";
    String[] arrOfStr = str.split("\n", 1);
     
    for (String a : arrOfStr)
          System.out.println(a);
    }
     
  6. GCNT

    GCNT Previously lukas.vdgaag

    How will this work? 'cause \n is a regex for enter...
     
  7. Yes you're right I don't use \n I use an @ this will work. 100%
     
  8. GCNT

    GCNT Previously lukas.vdgaag

    Thanks btw. This worked :)
     
  9. GCNT

    GCNT Previously lukas.vdgaag

    That's smart, but I wanna use the \n as most people know that as a line break regex/symbol.
     
  10. Yes you're right when you provide it for download that's the better way. Even if you write it your description most people won't read it.

    Have a nice Sunday :p
     
    • Like Like x 1
  11. GCNT

    GCNT Previously lukas.vdgaag

    Exactly that :p

    You too.
     

Share This Page