checking a palindrome sentance
Hi got a method to check if a string is a palindrome but not including spaces or punctuation for example:
"a,s dfdsa"
would be a palindrome. What I'm confused with is there a decent way in java to get rid of these spaces/punctuation? or is there something else that needs to be done?
The code I got so far would only work on something like "asdfdsa". (A string with no spaces or punctuation.
Heres my current code:
int strLeft = 0;
int strRight = str.length() -1;
while (strLeft < strRight) {
if (str.charAt(strLeft) != str.charAt(strRight)) {
return false;
}
strLeft++;
strRight--;
}
return true;
Thanks in advance