chaim chaim - 27 days ago 12
Android Question

how to read from file raw and use in String.format

I want to read data from a raw file and replace the format in the text.

For example... In a raw file like this:

hello {0}, my name id {1}, my age is {2}....


When I use String.format, as shown below, the text loses its indentation.

String data = readTextFile(this, R.raw.input);
data = String.format(data, "world", "josh", "3");


Does anyone know how to do this without losing indentation?

Answer Source

I found the solution for my problem.

there is a needed in one more variable, it's impossible to assignment into same variable

String data = readTextFile(this, R.raw.input);
String output = String.format(data, "world", "josh", "3");