1

The String is coming from an API response, when trying to display it on a TextView, \n and \t doesn't work. Here is the sample String:

ECONOMY\nBooking purchased under this fare type: \n\n-\tis ALLOWED to do a flight change up to 48 hours prior to the scheduled departure time subject to a change fee chargeable per passenger per sector, plus any fare difference applicable.\n-\tis NOT ALLOWED to do a name change.\n-\tis capacity controlled and limited and hence, may not be available on all flights.\n-\tis always subject to our General Terms and Conditions of Carriage & Fee Schedule (if applicable). \n

AL.
  • 36,815
  • 10
  • 142
  • 281
sillicon46
  • 41
  • 1
  • 9

3 Answers3

1
  String pureString = android.text.Html.fromHtml(fareRules).toString();
    String str1 = pureString.replace("[", "");
    str1 = str1.replace("]", "");
    str1 = str1.replace("\"", "");
    str1 = str1.replace("-", "");
    str1 = str1.replace("\\n", System.getProperty("line.separator"));
    str1 = str1.replace("\\t", getString(R.string.tab));
    ((TextView) dialog.findViewById(R.id.fare_rules)).setText(str1);
0

Try this.

string = string.replace("\\\n", System.getProperty("line.separator"));
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
Shubham
  • 521
  • 4
  • 11
0

use <br /> inplace of \n .

An option could be to wrap it in CDATA:

<string name="yourtest"><![CDATA[first line, <br />second line]></string>
DerStoffel
  • 2,553
  • 2
  • 15
  • 25