[PJUG Javamail] MessageFormat question

Karl karlkras at yahoo.com
Tue Jan 17 20:36:07 UTC 2012


Hey Michael (Late reply and assume this has already been put to bed),
Well, the MessageFormat utility would work fine here and personally don't hold a bias towards this over any other option. Your use of parens instead of curly brackets as per your message below, i.e., "{0}0-(1)-(2)", would be incorrect, but if you try this code here:

<code>

import java.text.MessageFormat;


public class testermod {
    private static String format_spec1 = "{0}-{1}-{2}";
    private static String format_spec2 = "{0}0-{1}-{2}";
    private static Object[] values = {"3182", "2300", "0000"};

    public static void main(String ... strs)
    {
        System.out.println(MessageFormat.format(format_spec1, values));
        System.out.println(MessageFormat.format(format_spec2, values));
    }
}

</code>

you'll see the results that I'm assuming you're after?




Message: 1
Date: Fri, 13 Jan 2012 15:52:49 -0800
From: Michael Phoenix <michaelandrewphoenix at gmail.com>
Subject: [PJUG Javamail] MessageFormat question
To: javamail at pjug.org
Message-ID:
    <CANo-2ahSTJRV+5tCSitD-9udeaywQRhhFLnZ-heob-_Xc9jD7A at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I'm trying to make a change to a message pattern that currently creates a
result of numbers from sources that are separated by dashes 3182-2300-0000
to adding a 0 before the first dash so that it looks like this
31920-2200-0000. when I try changing the pattern from "{0}-{1}-{2}" to
"{0}0-(1)-(2)" the formatter doesn't work, it just leaves the original
contents in the String that is the return value of the MessageFormat.format
method. Any ideas of what I need to do here?

Thanks,
Mike

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://javac.com/pipermail/javamail/attachments/20120117/0e3d8d42/attachment-0002.html>


More information about the Javamail mailing list