Skip to content

Instantly share code, notes, and snippets.

@muthugit
Created July 7, 2017 10:40
Show Gist options
  • Save muthugit/0b16bc622bd1aba6bfc98b8d7d2e35c0 to your computer and use it in GitHub Desktop.
Save muthugit/0b16bc622bd1aba6bfc98b8d7d2e35c0 to your computer and use it in GitHub Desktop.
/*
* AUTHOR: MU
* ORGANIZATION: WHIRLDATA
*
*/
import org.antlr.stringtemplate.*; // IMPORTING THE PACKAGES
import org.antlr.stringtemplate.language.*;
public class StringTemplateTest {
public static void main(String argsp[]) {
// PREPARING TEMPLATE WITH THE IDENTIFICATION USING $ SYMBOL
StringTemplate hello = new StringTemplate("Hello, $name$. The price of the $product$ is $price$ $currency$",
DefaultTemplateLexer.class);
// ASSIGN THE VALUES
hello.setAttribute("name", "John");
hello.setAttribute("price", 500);
hello.setAttribute("product", "car");
hello.setAttribute("currency", "INR");
// PRINT THE STRING
System.out.println(hello.toString());
}
}
// OUTPUT
// Hello, John. The price of the car is 500 INR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment