Jsp-jstl-function-indexof

提供:Dev Guides
移動先:案内検索

JSTL-fn:indexOf()関数

  • fn:indexOf()*関数は、指定された部分文字列の文字列内のインデックスを返します。

構文

  • fn:indexOf()*関数には次の構文があります−
int indexOf(java.lang.String, java.lang.String)

以下は、* fn:indexOf()*関数の機能を説明する例です-

<%@ 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 = "This is first String."/>
      <c:set var = "string2" value = "This <abc>is second String.</abc>"/>
      <p>Index (1) : ${fn:indexOf(string1, "first")}</p>
      <p>Index (2) : ${fn:indexOf(string2, "second")}</p>

   </body>
</html>

次の結果が表示されます-

Index (1) : 8
Index (2) : 13