troubleshooting Question

Convert ASCII codes to characters

Avatar of thomas908
thomas908 asked on
Fonts TypographyJava
51 Comments2 Solutions25793 ViewsLast Modified:

I have a ArrayList which contains a list of ASCII codes.
I want to convert all these ASCII codes into characters and place them in a String array.

This is the code I have written for this:



       
               
        ArrayList invalidCodesList = // contains all the relevant ASCII codes

        String [] invalidChars = new String[invalidCodesList.size()];
        for(int i=0; i<invalidCodesList.size(); i++) {
            int code = ((Integer)invalidCodesList.get(i)).intValue();
            invalidChars[i] = new Character((char)(code)).toString();
            Logger.getInstance().writeLog("ASCII code value is ----- "+code+"::::: character is ::  "+invalidChars[i]);
        }
           
   
The problem is that some of the ASCII codes are converted to values like ? and . rather than teh correct character.
Example
ASCII code value is ----- 135::::: character is ::  ?
- ASCII code value is ----- 136::::: character is ::  ?
- ASCII code value is ----- 137::::: character is ::  ?
- ASCII code value is ----- 139::::: character is ::  ?
- ASCII code value is ----- 141::::: character is ::  ?
- ASCII code value is ----- 143::::: character is ::  ?
- ASCII code value is ----- 144::::: character is ::  ?
- ASCII code value is ----- 149::::: character is ::  ?
- ASCII code value is ----- 150::::: character is ::  ?
- ASCII code value is ----- 151::::: character is ::  ?
- ASCII code value is ----- 152::::: character is ::  ?
- ASCII code value is ----- 153::::: character is ::  ?
- ASCII code value is ----- 155::::: character is ::  ?
- ASCII code value is ----- 157::::: character is ::  ?
- ASCII code value is ----- 160::::: character is ::   
- ASCII code value is ----- 168::::: character is ::  ¨
- ASCII code value is ----- 169::::: character is ::  ©
- ASCII code value is ----- 170::::: character is ::  ª
- ASCII code value is ----- 171::::: character is ::  «
- ASCII code value is ----- 172::::: character is ::  ¬
- ASCII code value is ----- 173::::: character is ::  ­
- ASCII code value is ----- 174::::: character is ::  ®
- ASCII code value is ----- 175::::: character is ::  ¯
- ASCII code value is ----- 177::::: character is ::  ±
- ASCII code value is ----- 178::::: character is ::  ²
- ASCII code value is ----- 179::::: character is ::  ³
- ASCII code value is ----- 183::::: character is ::  ·
- ASCII code value is ----- 184::::: character is ::  ¸
- ASCII code value is ----- 185::::: character is ::  ¹
- ASCII code value is ----- 186::::: character is ::  º
- ASCII code value is ----- 187::::: character is ::  »
- ASCII code value is ----- 188::::: character is ::  ¼
- ASCII code value is ----- 189::::: character is ::  ½
- ASCII code value is ----- 190::::: character is ::  ¾

Please help me resolve this.
ASKER CERTIFIED SOLUTION
bpmurray

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 51 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 51 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros