name.contains()

Discussion in 'Plugin Development' started by tommycake50, Sep 8, 2012.

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

    tommycake50

    well if i want to check if a player has a certain character in their name,
    do i have to do if(name.contains(" ") || name.contains("/") etc){
    }
    or can i do
    if(name.contains("?!/>*/,.<`*=+|(]*؍؀؁؂؃؄؆؇؈؉ؓؒؑؐ؏؎؍؋؊ؘؙؚؔؕؖؗ؞ؠةبائإؤأآءتثجحخدذرز")){
    }?
     
  2. Offline

    Assult

    Not quite sure, u tried name.contains("a", "s", "d"); ?
     
  3. Offline

    kyle1320

    You should be able to check for strings of characters, for example my IGN is kyle1320 so if you did
    Code:
    if (name.contains("1320")){
        //whatever
    }
    for my name it should run whatever you put
     
  4. Offline

    tommycake50

    it says it needs to be a charsequence i have no idea what that is.
     
  5. Offline

    Sagacious_Zed Bukkit Docs

  6. Offline

    gregthegeek

    I'm pretty sure you need to do it character by character with ||, unless you want to match all those characters in that specific order. For example, using my name (gregthegeek) if you tried to do contains("g") it would return true. If you tried contains("greg"), it would also return true. But if you did contains("gk") it would return false, as while there is a 'g' and a 'k' in my name, they are not next to each other like they are in the parameter you passed.

    Edit: Oh and a String is a type of CharSequence, so just pass in a String and you'll be fine.
     
  7. Offline

    tommycake50

    yeah i was trying to do if it contained any of the listed symbols so i think your right greg.
     
Thread Status:
Not open for further replies.

Share This Page