String Index Of
FreeMarker is a java based template engine for complex template processing.
This requires the library freemarker-2.3.16.jar to be in classpath.
The following example shows using String index_of built-in function.
package com.bethecoder.tutorials.freemarker.tests;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class StringIndexTest {
/**
* @param args
* @throws IOException
* @throws TemplateException
*/
public static void main ( String [] args ) throws IOException, TemplateException {
//Get template from classpath
Configuration cfg = new Configuration () ;
cfg.setClassForTemplateLoading ( StringIndexTest.class, "/" ) ;
Template template = cfg.getTemplate ( "strindex.ftl" ) ;
//Prepare data model
Map<String, Object> dataModel = new HashMap<String, Object> () ;
//Merge template and data
StringWriter output = new StringWriter () ;
template.process ( dataModel, output ) ;
System.out.println ( output.toString ()) ;
}
}
It gives the following output,
index_of
-----------
3
7
-1