Handling ASCII character set in Java (II)
7 February 2008This post is in continuation of “Handling ASCII character set in Java (I)”. In this post, I will talk about how to validate input according to ASCII character set.
As I have already written, ASCII has only 93 printable characters with ASCII codes from 33 till 126 (inclusive). Lets see how to validate input according to ASCII printable characters.
I have written a method that can be used for validation:
public static ArrayList<String> valiateCharacterSetAscii(ArrayList<String>fileContents){ ArrayList <String>tmpList = new ArrayList<String>(); String str = ""; for(int j=0; j < fileContents.size();j++) { str = fileContents.get(j); String resultantString = ""; for(int i=0;i<str.length();i++){ int charCode = (int)str.charAt(i); if( ((charCode>=33 && charCode <=126))) resultantString += str.charAt(i); else resultantString += null; } tmpList.add(resultantString); } return tmpList; }
The method above replaces non ASCII printable characters with null. You may replace null with any character.
Do read the next part of this topic.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Handling ASCII character set in Java (II)