Hi Friends,
I want to initialise a byte array of 20 bytes and then fill a string into it,I want the rest of the array filled with spaces,so i tried this but its not working:
byte[] userarray = new byte[20];
for(int i=0;i<userarray.length;i++){
userarray[i] = '\32';
}
String user = "any user";
try{
userarray = user.getBytes("US-ASCII");
}
}catch(Exception e){e.printStackTrace();}
//Print out the byte array contents
for(int i=0;i<userName.length;i++){
System.out.println("userarray["+i+"]"+userarray);
}
OUTPUT:
userarray[0] 97
userarray[1] 110
userarray[2] 121
userarray[3] 32
userarray[4] 117
userarray[5] 115
userarray[6] 101
userarray[7] 114
Why not???
userarray[0] 97
userarray[1] 110
userarray[2] 121
userarray[3] 32
userarray[4] 117
userarray[5] 115
userarray[6] 101
userarray[7] 114
userarray[8] 32
userarray[9] 32
..
..
..
userarray[19] 32
any help would be appreciated.