Using only alphanumeric characters(a-z) inside toCharArray

Below you will find me using toCharArray in order to send a string to array. I then MOVE the value of the letter using a for statement...

for(i = 0; i < letter.length; i++){
               letter[i] += (shiftCode);
               System.out.print(letter[i]);
            }

However, when I use shiftCode to move the value such as...

a shifted by -1; I get a symbol @. Is there a way to send the string to shiftCode or tell shiftCode to ONLY use letters? I need it to see my text, like "aaron", and when I use the for statement iterate through a-z only and ignore all symbols and numbers. I THINK it is as simple as...

letter=codeWord.toCharArray(a,z);

But trying different forms of that and googling it didn't give me any results. Perhaps it has to do with regex or something? Below you will find a complete copy of my program; it works exactly how I want it to do; but it iterates through letters and symbols. I also tried finding instructions online for toCharArray but if there exists any arguments I can't locate them.

My program...

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*
 * Aaron L. Jones
 * CS219
 * AaronJonesProg3
 * 
 * This program is designed to -
 * Work as a Ceasar Cipher
 */

/**
 *
 * Aaron Jones
 */
public class AaronJonesProg3 {
    static String codeWord;
    static int shiftCode;
    static int i;
    static char[] letter;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // Instantiating that Buffer Class
        // We are going to use this to read data from the user; in buffer
        // For performance related reasons
        BufferedReader reader;

        // Building the reader variable here
        // Just a basic input buffer (Holds things for us)
        reader = new BufferedReader(new InputStreamReader(System.in));

        // Java speaks to us here / We get it to query our user
        System.out.print("Please enter text to encrypt: ");

        // Try to get their input here
        try {    
            // Get their codeword using the reader
            codeWord = reader.readLine();

            // Make that input upper case
            codeWord = codeWord.toUpperCase();
            // Cut the white space out
            codeWord = codeWord.replaceAll("\\s","");
            // Make it all a character array
            letter = codeWord.toCharArray();
        }
        // If they messed up the input we let them know here and end the prog.
        catch(Throwable t) {
            System.out.println(t.toString());
            System.out.println("You broke it. But you impressed me because"
                    + "I don't know how you did it!");
        }

        // Java Speaks / Lets get their desired shift value
        System.out.print("Please enter the shift value: ");

        // Try for their input
        try {
               // We get their number here
               shiftCode = Integer.parseInt(reader.readLine());
        }
        // Again; if the user broke it. We let them know.
        catch(java.lang.NumberFormatException ioe) {
            System.out.println(ioe.toString());
            System.out.println("How did you break this? Use a number next time!");
        }

        for(i = 0; i < letter.length; i++){
           letter[i] += (shiftCode);
           System.out.print(letter[i]);
        }

        System.out.println();

        /****************************************************************
         ****************************************************************
         ***************************************************************/
        // Java speaks to us here / We get it to query our user
        System.out.print("Please enter text to decrypt: ");

        // Try to get their input here
        try {    
            // Get their codeword using the reader
            codeWord = reader.readLine();

            // Make that input upper case
            codeWord = codeWord.toUpperCase();
            // Cut the white space out
            codeWord = codeWord.replaceAll("\\s","");
            // Make it all a character array
            letter = codeWord.toCharArray();
        }
        // If they messed up the input we let them know here and end the prog.
        catch(Throwable t) {
            System.out.println(t.toString());
            System.out.println("You broke it. But you impressed me because"
                    + "I don't know how you did it!");
        }

        // Java Speaks / Lets get their desired shift value
        System.out.print("Please enter the shift value: ");

        // Try for their input
        try {
               // We get their number here
               shiftCode = Integer.parseInt(reader.readLine());
        }
        // Again; if the user broke it. We let them know.
        catch(java.lang.NumberFormatException ioe) {
            System.out.println(ioe.toString());
            System.out.println("How did you break this? Use a number next time!");
        }

        for(i = 0; i < letter.length; i++){
           letter[i] += (shiftCode);
           System.out.print(letter[i]);
        }

        System.out.println();
    }
}

Answers


Use Character.isLetter() to separate out the Letters.......

See this link.....

http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html

Eg:

public class Test{
   public static void main(String args[]){
      System.out.println( Character.isLetter('c'));
      System.out.println( Character.isLetter('5'));
   }
}

Output:

true false


Need Your Help

SQL Triggers: Are they fired after a statement or a transaction?

sql transactions triggers

I'm looking for an answer to whether triggers in SQL are fired immediately following an action caused by a statement, or only after the entire transaction is committed?

How do I replace a character with a graphic (emoji) in XSLT / FO?

xml xslt replace xsl-fo emoji

I've seen similar, but not quite questions as this, but here is what I'm trying to do. I have the XML from my SMS, and from it, create a PDF log. Works great. Tried to add this new element, and ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.