Removing last characters in string

Discussion in 'Spigot Plugin Development' started by Epixel, Mar 27, 2018.

  1. Hello, I'm making a /list plugin, and I'm trying to remove the last few characters in the string so it doesn't say ", " at the end of the last name.
    Code (Text):

                String viewplayers = allplayers.trim(); //This is the string that has all the players.
                String finalviewplayers = viewplayers.substring(0, viewplayers.length() -2); //When I try removing the last 2 letters, it replaces them with an "r" for no reason.
     
     
  2. Code (Java):
    private static String removeLastChar(String str) {
      return str.trim().substring(0, str.length() - 1);
     }

    private void use() {
      String s = removeLastChar("hello, there, you, "); // "hello, there, you"
    }