Java Message Format format(String str, Object... arguments)

Here you can find the source of format(String str, Object... arguments)

Description

Formats UI strings.

License

Open Source License

Parameter

Parameter Description
str The string to format
arguments Arguments to use in formatting the string

Return

The formatted string

Declaration

public static String format(String str, Object... arguments) 

Method Source Code


//package com.java2s;
/* *************************************************************************
 *
 *  TMPotter - Bi-text Aligner/TMX Editor
 *
 *  Copyright (C) 2015 Hiroshi Miura/*www  .  ja  v a2 s  .  com*/
 *
 *  This file come from OmegaT project
 * 
 *  Copyright (C) 2007 - Zoltan Bartko
 *                2011 Alex Buloichik
 *
 *  This file is part of TMPotter.
 *
 *  TMPotter is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  TMPotter is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with TMPotter.  If not, see http://www.gnu.org/licenses/.
 *
 * *************************************************************************/

import java.text.MessageFormat;

public class Main {
    /**
     * Formats UI strings.
     * <p>
     * Note: This is only a first attempt at putting right what goes wrong in
     * MessageFormat. Currently it only duplicates single quotes, but it doesn't
     * even test if the string contains parameters (numbers in curly braces),
     * and it doesn't allow for string containg already escaped quotes.
     *
     * @param str       The string to format
     * @param arguments Arguments to use in formatting the string
     * @return The formatted string
     * @author Henry Pijffers (henry.pijffers@saxnot.com)
     */
    public static String format(String str, Object... arguments) {
        str = str.replaceAll("'", "''");
        return MessageFormat.format(str, arguments);
    }
}

Related

  1. format(String message, Object... params)
  2. format(String pattern, Map params)
  3. format(String pattern, Object... args)
  4. format(String pattern, String[] replacements)
  5. format(String str, int replacement)
  6. format(String textPattern, Object... args)
  7. formatAsNumber(double value)
  8. formatCause(final String message, final Throwable cause, final Object... args)
  9. formatDuring(long mss, String pattern)