How to convert ASCII values that are substring inside a string to its character? For example:
If I give input as
H105 68u100e33 65r101 89o117?
I need output as
Hi Dude! How Are You?
In the above input after every alphabet or spaces there is an ASCII value.
char[] a = new char[2];
char t;
String temp,output="";
for(int i=0;i<str.length()-1;i++){
a[0]=str.charAt(i);
a[1]=str.charAt(i+1);
if(Character.isDigit(a[0])){
if(Character.isDigit(a[1])){
String con=String.valueOf(a[0])+String.valueOf(a[1]);
int n=Integer.parseInt(con);
output=output+(char)n;
}else{
//nothing
}
}else{
output=output+a[0];
}
}
System.out.println("output : "+output);
I have tried something like this, and it fails at 3 digit ASCII values and also sometimes I face array index outofbound error due to charAt(i+1) statements.
How to change that ASCII values to its char and form a sentence?