MattGotJava
MattGotJava

Reputation: 185

How to make a Scanner in Java not care about punctuation

I know how to make a Java Scanner not care about the uppercase or lowercasing, but how do I make it so that it doesn't care about punctuation? I want to do this so that I don't have to type all of this:

if (mirioutput.equalsIgnoreCase("You're an idiot.") ||
    mirioutput.equalsIgnoreCase("Your an idiot.") ||
    mirioutput.equalsIgnoreCase("You're an idiot") ||
    mirioutput.equalsIgnoreCase("Youre an idiot") ||)
{
     //code goes here
}

By the way, I'm trying to make a Siri-like program that will respond to what you type, if you're wondering why the text says "You're an idiot."

Upvotes: 0

Views: 95

Answers (2)

SSC
SSC

Reputation: 3008

You need to look at Scanner's delimeter and findInLine functions.

Upvotes: 0

Amer Qarabsa
Amer Qarabsa

Reputation: 6574

you can remove all none alphabatical and digits characters

      mirioutput = mirioutput.replaceAll("[^A-Za-Z9-0]","");

Upvotes: 2

Related Questions