Monday, March 29, 2010

Importent Programming Stuff

Identifying Special Characters in a Given String
-------------------------------------------------------------------------------------------------

package special;

public class IdentifySpecialChar {

/**
* @param args
*/
public static void main(String[] args) {

try {
System.out.println(IdentifySpecialChar.identifyingSpecialCharacters("Gangadhar"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
* This method is used to identify the special characters in the given value,
* if there are any special characters it return true else return false.
* @param value
* @return
* @throws Exception
*/
public static boolean identifyingSpecialCharacters(String value) throws Exception {
boolean returnVal = false;
char[] charArray = value.toCharArray();
for(int i=0;i< charArray.length;i++) {
System.out.println((int)charArray[i]);
if( (((int)charArray[i]) >= 32 && ((int)charArray[i]) <= 47) ||
(((int)charArray[i]) >= 58 && ((int)charArray[i]) <= 64) ||
(((int)charArray[i]) >= 91 && ((int)charArray[i]) <= 96) ||
(((int)charArray[i]) >= 123 && ((int)charArray[i]) <= 127)) {
returnVal = true;
break;
}
}
return returnVal;
}
}