Why am I not able to print the escape sequence in editext in Android?
I am getting a response from the API using an HTTP POST request that contains some escape sequences like \ n, \ t, etc. When I try to display it in editText it shows up as \ n and \ t, but I expect a new line or horizontal tab. This is my code:
String out1 = sys.getString("stdout");
Toast.makeText(getApplicationContext(), out1, Toast.LENGTH_LONG).show();
String time1 = sys.getString("time");
if(compile.length()>0 && time1.equalsIgnoreCase("null")){
et.setText("Compilation error "+"\n"+compile);
}
else if(compile.length()>0){
et.setText("Runtime error "+"\n"+compile);
}
else
et.setText(message.substring(2,message.length()-2)+" time: "+time1.substring(1,Math.min(time1.length(),4))+" memory: "+mem.substring(1,mem.length()-1)+"\n"+out1.substring(2,out1.length()-2));
//et.setText(result);
} catch(Exception e){
e.printStackTrace();
}
The stdout object of the JSON object is something like "stdout": ["5 \ n6"], and when I print it to editText, it displays 5 \ n6, but I'm expecting a new line. Is there a way to handle all the escape sequences to display the result correctly. I have tried this for quite a while but cannot find a solution. Please guide me. Thanks in advance!
+3
source to share
2 answers