Easy Tutorial
❮ Jsp Auto Refresh Jsp Javabean ❯

fn:trim() Function

JSP Standard Tag Library

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>

&lt;c:set var="string1" value="I am from tutorialpro         "/>
<p>Length of string1 : ${fn:length(string1)}</p>

&lt;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

JSP Standard Tag Library

❮ Jsp Auto Refresh Jsp Javabean ❯