<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> JSTL Functions • String Subset

String Subset

fn:substring

Input String beginIndex endIndex Result
${zip} 6 -1 P.O. Box: ${fn:substring(zip, 6, -1)}
${s1} 11 17 ${fn:substring(s1, 11, 17)}
${s1} 12 5  ${fn:substring(s1, 12, 5)}
${s1} 23 -1 ${fn:substring(s1, 23, -1)}
${s1} 23 999 ${fn:substring(s1, 23, 999)}
${s1} -1 -1 ${fn:substring(s1, -1, -1)}
${s1} 99 12  ${fn:substring(s1, 99, 12)}
empty string 2 6  ${fn:substring("", 2, 6)}
null 2 6  ${fn:substring(undefined, 2, 6)}

fn:substringAfter

Input String substring Result
${zip} - P.O. Box: ${fn:substringAfter(zip, "-")}
${s1} There ${fn:substringAfter(s1, "There")}
${s1} on a ${fn:substringAfter(s1, "on a")}
${s1} not found  ${fn:substringAfter(s1, "not found")}
${s1} null ${fn:substringAfter(s1, undefined)}
${s1} empty string ${fn:substringAfter(s1, "")}
empty string castle  ${fn:substringAfter("", "castle")}
null castle  ${fn:substringAfter(undefined, "castle")}
null empty string  ${fn:substringAfter(undefined, "")}

fn:substringBefore

Input String substring Result
${zip} - Zip without P.O. Box: ${fn:substringBefore(zip, "-")}
${s1} on a ${fn:substringBefore(s1, "on a")}
${s1} castle ${fn:substringBefore(s1, "castle")}
${s1} null  ${fn:substringBefore(s1, undefined)}
${s1} empty string  ${fn:substringBefore(s1, "")}
empty string castle  ${fn:substringBefore("", "castle")}
null castle  ${fn:substringBefore(undefined, "castle")}
null empty string  ${fn:substringBefore(undefined, "")}