JSTL Functions - trim()

The fn:trim() function removes white space from both ends of a string.

Syntax:

The fn:trim() function has following syntax:

java.lang.String trim(java.lang.String)

JSTL Example :

<%@ 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>JSTL Tutorial</title>
</head>
<body>
<c:set var="str1" value=" www.c4learn.com    "/>
<p>Str1 Length : ${fn:length(str1)}</p>
<c:set var="str2" value="${fn:trim(str1)}" />
<p>Str2 Length : ${fn:length(str2)}</p>
<p>Output string : ${str2}</p>
</body>
</html>

Output :

Str1 Length : 20
Str2 Length : 15
Output string : www.c4learn.com