Jsp-jstl-function-replace

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

JSTL-fn:replace()関数

  • fn:replace()*関数は、文字列のすべての出現を別の文字列に置き換えます。

構文

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

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

<%@ 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 = "${fn:replace(string1, 'first', 'second')}"/>
      <p>Final String : ${string2}</p>
   </body>
</html>

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

Final String : This is second String.