Solved Special symbol $

Discussion in 'Plugin Development' started by Straiker123, Jun 27, 2019.

Thread Status:
Not open for further replies.
  1. Hello, I need your help with the '$' symbol, always throws an error in commands and chat (if chat is modified by event.setFormat) I've tried: string = string.replaceAll ("\\$", "\\\\\\$"); but then I had it in TabList \$ and in the commands as well.
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. In replace colors in string ->
    public static String color(String string) {
    string= string.replaceAll("\\$","\\\\\\$");
    return ChatColor.translateAlternateColorCodes('&', string);
    }}
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Straiker123 Can't you just keep it in without replacing it? And if you can't then please post the error that you get.
     
  5. Offline

    Kars

    Double backslash results in the second backslash being escaped, and the $ remaining as is.

    $ is an error in Java. \$ is a dollar sign. \\$ is a backslash and an error.

    Use a single backslash.
     
  6. Error -> Invalid escape secquence in string.replaceAll("\\$","\$"<--- here );

    and error.. error is in chat, commands..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 27, 2019
  7. Offline

    Kars

    @Straiker123 Like i said...

    Using a double backslash in a string will cause that error. Use a single backslash everywhere. You can not once use "\\$". It will error.

    Or you can do this:
    PHP:
    StringEscapeUtils.escapeJava("the string you want to escape. \\$")
    That way you don't need to escape at all. Just use escapeJava whenever you handle input.
     
  8. Error in console if player send to chat '$', and colors not working -> \u00A74ServerControl \u00A7e>>> \u00A7rStraike
    r123 \u00A79left the game
    Code:
    public static String chat(String string) {
        string= StringEscapeUtils.escapeJava(string);
        return ChatColor.translateAlternateColorCodes('&', string);
    }}
    Edit: Fixed, i replace '.replaceAll("%message%, msg) with .replace("%message%", msg)', thank you for your time and help
     
    Last edited: Jun 28, 2019
Thread Status:
Not open for further replies.

Share This Page