Jump to content
Sign in to follow this  
KevinHouse

Chat to game text

Recommended Posts

Hello everyone,

I'll be sharing with you some code to convert a String obtained in chat to a String useable in methods.

You'll be removing all symbols and redundant characters of the String with:

String#replaceAll("[[^0-9]&&[^a-z]&&[^A-Z]]", "");

Remember to also use this in the filter when comparing with a space:

public String cleanThis(String s) {
    return s.replaceAll("[^A-Za-z0-9]", "");
}

RSPlayer[] zezima = Players.find(new Filter<RSPlayer>() {
    @Override
    public boolean accept(RSPlayer p) {
        return cleanThis(p.getName().toLowerCase()).equals(cleanThis("Z e zim a").toLowerCase());
    ;

This will ensure compatability between the chat spaces and the interface spaces.

Edited by KevinHouse
BB edit removed spaces and weird characters + Code suggestions
  • Like 1

Share this post


Link to post
Share on other sites
10 minutes ago, KevinHouse said:
public String cleanThis(String s) {
    return s.replaceAll("[[^0-9]&&[^a-z]&&[^A-Z]]", "");
}

RSPlayer[] zezima = Players.find(new Filter<RSPlayer>() {
    @Override
    public boolean accept(RSPlayer p) {
        if(cleanThis(p.getName().toLowerCase()).equals(cleanThis("Z e zim   a").toLowerCase())) {
            return true;
        }
        return false;
    ;

 

Don't really see this as a tutorial and more like a snippet.

Your regex can be replaced by with

[^A-Za-z0-9]

Your if statement can be replaced with this.

return cleanThis(p.getName().toLowerCase()).equals(cleanThis("Z e zim a").toLowerCase());

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
8 hours ago, Blastois3 said:

Don't really see this as a tutorial and more like a snippet.

Your regex can be replaced by with

[^A-Za-z0-9]

Your if statement can be replaced with this.

return cleanThis(p.getName().toLowerCase()).equals(cleanThis("Z e zim a").toLowerCase());

 

Thanks for your feedback! The suggestions are good.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×