Connecting Tech Pros Worldwide Forums | Help | Site Map

help on char array to ascii please

Newbie
 
Join Date: Nov 2008
Posts: 2
#1: Nov 25 '08
Expand|Select|Wrap|Line Numbers
  1. String hello = "james";
  2.         int[] ascii;
  3.         char[] letter = hello.toCharArray();
  4.         int j = letter.getLength();
  5.         for(int i = 0; i<=j; i++){
  6.             ascii = (int[]) letter[i];
  7.         }
  8.  
  9.         System.out.println(ascii);
  10.  
  11.  
this is what i have, i want the string to be converted into a char array and then into ascii which will be in an array, and no i cant use the getByte method

Newbie
 
Join Date: Nov 2008
Posts: 2
#2: Nov 25 '08

re: help on char array to ascii please


Expand|Select|Wrap|Line Numbers
  1. class Encoder{
  2.     public static void main(String[] arguments){
  3.  
  4.         String hello = "james";
  5.  
  6.         char[] letter = hello.toCharArray();
  7.  
  8.         int[] ascii = new int[letter.length];        
  9.  
  10.         for(int i = 0; i<letter.length; i++){
  11.             ascii[i] = (int)letter[i];
  12.         System.out.println(ascii[i]);
  13.         }
  14.  
  15.  
  16.  
  17.     }
  18. }
Reply


Similar Java bytes