Android Utililty Methods String Format

List of utility methods to do String Format

Description

The list of methods to do String Format are organized into topic(s).

Method

Stringformat(String str, String obj)
format
if (str == null || obj == null)
    return str;
return replace(str, "{0}", obj);
Stringformat(String str, String[] obj)
format
if (str == null || obj == null)
    return str;
for (int i = 0; i < obj.length; i++)
    str = replace(str, "{" + i + "}", obj[i]);
return str;
Stringformat(String str, Object... obj)
format
if (str == null || obj == null)
    return str;
for (int i = 0; i < obj.length; i++)
    str = replace(str, "{" + i + "}", String.valueOf(obj[i]));
return str;
Stringformat(String str, Object... args)
format
if (isEmpty(str))
    return "";
if (args.length == 0)
    return str;
String result = str;
Pattern p = java.util.regex.Pattern.compile("\\{(\\d+)\\}");
Matcher m = p.matcher(str);
while (m.find()) {
...
StringsimpleFormat(String s, Object aobj[])
simple Format
String as[] = s.split("%s");
String s1;
if (as.length < 2) {
    s1 = s;
} else {
    StringBuilder stringbuilder = new StringBuilder();
    int i = aobj.length;
    int j = 0;
...
Stringformat(String str, Object... args)
format
if (isEmptyOrNull(str))
    return "";
if (args.length == 0)
    return str;
String result = str;
Pattern p = java.util.regex.Pattern.compile("\\{(\\d+)\\}");
Matcher m = p.matcher(str);
while (m.find()) {
...
StringformatAccountNo(String accountNo)
format Account No
try {
    StringBuffer s = new StringBuffer();
    for (int i = 0; i < accountNo.length() - 10; i++) {
        s.append("*");
    StringBuffer sb = new StringBuffer(accountNo);
    sb.replace(6, accountNo.length() - 4, s.toString());
    return sb.toString();
...
StringformattedNumber(String number)
formatted Number
if (number == null)
    return "0";
String fn = "0";
if (isNumber(number)) {
    DecimalFormat df = new DecimalFormat("#,##0");
    fn = df.format(Double.parseDouble(number));
return fn;
...
CharSequencecurrentTime(CharSequence inFormat)
current Time
return DateFormat.format(inFormat, System.currentTimeMillis());
StringformatIndent(String whiteSpace)
Formats the indent so that it uses as many tabs as possible
int tabs, spaces, newTabs;
char chTemp;
String strTemp, ret;
tabs = 0;
spaces = 0;
newTabs = 0;
ret = "";
for (int i = 0; i < whiteSpace.length(); i++) {
...