Latest web development tutorials

JSTLは、fn:サブストリング()関数

JSP標準タグライブラリ JSP標準タグライブラリ

FN:サブストリング()関数は、サブストリング索引の文字列指定した開始と終了を返します。

文法

FN:()構文substring関数は次のとおりです。

${fn:substring(<string>, <beginIndex>, <endIndex>)}

例のデモ

次の例は、この関数の機能を示します。

<%@ 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>使用 JSTL 函数</title>
</head>
<body>

<c:set var="string1" value="This is first String."/>
<c:set var="string2" value="${fn:substring(string1, 5, 15)}" />

<p>生成的子字符串为 : ${string2}</p>

</body>
</html>

結果は以下のとおりであります:

生成的子字符串为 : is first S

JSP標準タグライブラリ JSP標準タグライブラリ