DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2005
    Posts
    7

    Taking out non-letters

    I'm am currently making a Palindrome program that checks to see if the entered string is a palindrome and if it is not checks if it is a almost-palindrome. An almost-palindrome is defined(by the book) is a palindrome once you remove all punctuation characters and such. I am having trouble doing this using a normal string and/or StringBuffer. This is what I am trying:

    Code:
    for(int c=0;c<sb.length();c++)
    		{
    			if((sb.charAt(c)<'a' || sb.charAt(c)>'z')&&(sb.charAt(c)<'A' || sb.charAt(c)>'Z'));
    			{
    				sb.deleteCharAt(c);
    			}
    		}
    Any suggestions would be appreciated.

  2. #2
    Join Date
    Dec 2003
    Location
    tx/us
    Posts
    131
    Meditate on Character.isLetter().

  3. #3
    Join Date
    May 2005
    Posts
    7
    Wow, I feel stupid...I accidently put a semi-colon after my if statement

    Thanks for the help, Ray.
    Last edited by nrz; 05-25-2005 at 05:00 PM.

  4. #4
    Join Date
    Dec 2003
    Location
    tx/us
    Posts
    131
    Wow, I feel stupid not seeing that but I'll lay it on the late hour reply. Still isLetter() is probably the best way to test.

  5. #5
    Join Date
    May 2005
    Posts
    7
    Yep, it's all working correctly now. That makes two of us that should have caught the mistake .

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links