I am getting a response from an API using HTTP POST request which contains which contains some escape sequences such as \n, \t etc. When i try to display it in editText it is displayed 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 JSON object stdout is something like "stdout":["5\n6"] and on printing it in editText it displays 5\n6 but i expect a new line. Is there any way to handle all escape sequences so as to properly display the result. I have been trying this for quite a while but cannot find a solution. Please guide me. Thanks in advance !!
First, set your editText in xml file like this:
now put your text with new line character -
This works, enjoy!!!
Replace
out1.substring(2,out1.length()-2)
without1
.