CyberArmy University | Open Source Institute | CyberArmy Intelligence & Security | CyberArmy Services & Projects

correction made


[Replies] [Reply] [View by Thread] [Help]
[Back To SNEAK Development Forum]

Posted by Cpt SAJChurchey On 2005-03-07 21:41:14
In Reply to What about replacing hex2decimal() by... Posted by Tr flamebalrog On 2005-03-06 00:15:30

Cpt
Cpt SAJChurchey


public static String hex2Text(String str){
          if(str == null || str.trim().length() == 0)
            return "";
          str = str.trim().toLowerCase();
          if(str.matches("[^0-9a-f\\s]")){
                /*
                  User needs to be warned that their input is invalid
                  Method must terminate
                */
                return "";  //Until proper exception can be written
          }
          StringTokenizer tokenizedStr = new StringTokenizer(str);
          StringBuffer text = new StringBuffer();
          while(tokenizedStr.hasMoreTokens()){
                String hexString = tokenizedStr.nextToken();
                int bytelen = hexString.length();
                if(bytelen > 4){
                 //User needs to be told input is not valid
                 return ""; //Until exception can be written.
                }
                int  decimal = Integer.parseInt(hexString,16);
                char textEquivalent = (char) decimal;
                text.append(textEquivalent);
          }//end while
          return text.toString();
        }
Cpt SAJChurchey
C/O of
Editorial
OSI Staff edit0r
OSI Feedback Representative




Replies:


Guest:
Subject:
Message:
Signature:
Optional Image Link:
http://

CyberArmy::Forum v0.6
Generated In 0.02339 seconds


About Us | Privacy Policy | Mission Statement | Help