Special characters not accepted?

Discussion in 'Plugin Development' started by Thej0y, May 15, 2013.

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

    Thej0y

    Hi, i got a problem with the character "$" in a command.

    Code:
    if(args[0].equals("$")){
    // do something
    }
    for some reason, its not working. is there a special sequance for it? ( like in html for "é" its "é")

    also, is there a "universal money thing" to detect if its any money "logo" or i should just do
    Code:
    if(args[0].equals("$") || args[0].equals("€")){ //and so on
    // do something
    }
    Thanks :)
     
  2. Offline

    FuZioN720

    Putting "$" makes it a string or like a message so that doesn't have to with java so there is no Special thing you have to do like HTML as far as I know.

    Also i think the best way is to do what you are doing in the second code. using the or (||) it might be longer but it will work.
     
  3. Offline

    caseif

    Try echoing out args[0] just to verify that it's the correct string. To answer your second question, you would need to create a List (probably of chars) that contained every character you consider a "money logo," then check if args[0] is contained by that List.
     
  4. Offline

    Thej0y

    so there is no way I can detect if the "args[]" is a "$"?
    so if I do
    Code:
    Public String DollarSign = "$";
    its like doing
    Code:
    Public String DollarSign = new String;
    // which i know its not acceptable :P
    ?

    there is surely a way to use "$" in java.. i cant believe that java cant be used with curencies :p

    Edit:
    AngryNerd
    gonna try that :)

    The string return: $ .. as it should
    But somehow it does not pass for ".equals ("$")".. :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  5. Offline

    Icyene

    If you are sure that the String returned is '$', attempt a .trim() call before .equals(): there may be (in an unlikely case) some trailing or leading whitespace.
     
  6. Offline

    Thej0y

    The actual command is:
    Code:
    if(args[0].equalsIgnoreCase("money") || args[0].equals("$")){
    // do something
    }
    It work good with "money" but dont work with "$". the command return to sender where is the error and which String or Integer couldnt pass... and the word that dont pass is "$" in args[0] ..
    I also added:
    Code:
    sender.sendMessage(ChatColor.GOLD + " " + args[0] + " " + args[1] + " " + args[2] + " " + args[3] + " " + args[4]);
    in case of error, but it return a correct sequence... :S i'm troubled XD

    Why .equals ("$") wouldnt accept a String which contain only $
     
  7. Offline

    lol768

    Why would a command argument have leading or trailing whitespace? Aren't the args generated from a string split by space characters?
     
  8. Offline

    Icyene

    "in an unlikely case"

    Yes, that is the expected result. However, we do not know what fork of CraftBukkit he may be using, and I know of at least one fork (which shall remain nameless) which did, at one point, have such an issue. Additionally, as `"$".equals("$")` returns true, as expected, this leads one to the conclusion that args[0] is not just "$".
     
  9. Try
    Code:java
    1.  
    2. if(args[0].equalsIgnoreCase("$"){
    3. //Do code
    4. }
    5.  
     
Thread Status:
Not open for further replies.

Share This Page