Pages

Monday, May 29, 2017

String Formatting in Android

String Formatting in Android 
 
This post is about having the String Formatting in Android. 
StringBuilder Class can be used
 
A Sample Code is given below.
 
final StringBuilder bootMsg = new StringBuilder();
String Sender="Sender";
String RX="Receiver"
String Id="121212121ds-afdsfdsafdsf";

bootMsg.append(String.format("<message from=\"%s\" to=\"%s\" type=\"normal\" id=\"%s\">", Sender, Rx, Id));
bootMsg.append("<TAG></TAG>");
 
 
Output will be ,
 
<message from="Sender" to="Receiver" type="normal" id="121212121ds-afdsfdsafdsf">
<TAG></TAG> 

Reference
 
https://stackoverflow.com/questions/12169826/android-string-format-with-double-value

No comments:

Post a Comment