fn:trim() Function
The fn:trim() function removes whitespace characters from both ends of a string.
Syntax
The syntax for the fn:trim() function is as follows:
${fn:trim(<string>)}
Example Demonstration
The following example demonstrates the function's capabilities:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
<title>Using JSTL Functions</title>
</head>
<body>
<c:set var="string1" value="I am from tutorialpro "/>
<p>Length of string1 : ${fn:length(string1)}</p>
<c:set var="string2" value="${fn:trim(string1)}" />
<p>Length of string2 : ${fn:length(string2)}</p>
<p>String is : ${string2}</p>
</body>
</html>
The output is as follows:
Length of string1 : 25
Length of string2 : 16
String is : I am from tutorialpro