Android String.format() Returns Question Mark (??) [FIXED] -
i have app downloads files internet. source file name dynamically generated depending on user selection. use following method create source file name. note fileid
integer (1-99).
final string filename = "file_" + string.format("%02d", fileid) + "_download.jpg";
the issue have seen users unable download files (and of course leave 1 start ratings :( ). when check server log see download requests came file names file_??_download.jpg
. looks string.format()
has returned ??
instead of 2 digit number.
i searched everywhere , not find solution this. can tell me what's wrong code? not re-produce error on of devices.
thanks!
you have instead:
final string filename = "file_" + string.format("%d", fileid) + "_download.jpg";
or
final string filename = "file_" + fileid + "_download.jpg";
if want 2 last digits, it:
int formattedfileid = fileid % 100; final string filename = "file_" + (formattedfileid < 10 ? '0' : '') + string.format("%d", formattedfileid) + "_download.jpg";
or
int formattedfileid = fileid % 100; final string filename = "file_" + (formattedfileid < 10 ? '0' : '') + formattedfileid + "_download.jpg";
Comments
Post a Comment