JSTL fn:join() and fn:split() function

JSTL fn:join():

The JSTL fn:join() function concatenates the all array elements with a specified separator.
Syntax: String join (String[] inputArray, String separator)

JSTL fn:split():

The JSTL fn:split() function splits the given string into an array of substrings based on the specified delimiter string.
Syntax: String[] split(String givenString, String specifiedDelimiter)


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
  <title>fn:split and fn:join JSTL function example</title>
  <c:set var="testString" 
                          value="Hello this is a JSTL function example."/>
  String before splitting: <br/>
  <c:out value="${testString}" />
  <c:set var="testStringAfterSplitting" 
                              value="${fn:split(testString, ' ')}"/><br/>
  <c:set var="testStringAfterJoining" 
                 value="${fn:join(testStringAfterSplitting, '-')}"/><br/>
  String after split and join operation:<br/>  
  <c:out value="${testStringAfterJoining}" />


No comments: