MessageFormat parse Example

MessageFormat class parse example. This example shows you how to use parse method.


MessageFormat class parse example. public Object[] parse(String source, ParsePosition pos) Parses the string. Caveats: The parse may fail in a number of circumstances.

Here is the code
/*
 * @ # Parse1.java
 * A class repersenting use to parse method 
 * of MessageFormat class in java.text package
 * version 19 June 2008
 * author Rose India 
 */

import java.text.*;

public class Parse1 {

    public static void main(String[] args) {
        // Create a pattern for our MessageFormat object to use.
        String pattern = "I bought {0,number,#} " +
                "apples for {1,number,currency} " +
                "on {2,date,dd-MMM-yyyy}.";

        // Create a MessageFormat object and apply the pattern
        // to it.
        MessageFormat mFmt = new MessageFormat(pattern);
        Object[] values = null;


        values = mFmt.parse("I bought 20 apples for $14.18 " +
                "on 01-Nov-2007.",new ParsePosition(10));

        // Print out the pattern being used for formatting
        // and the formatted output.
        System.out.println(mFmt.format(values));
    }
}

Output

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US