English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JSTL fn:contains()-Funktion

JSP-Standard-Tag-Bibliothek

Die fn:contains()-Funktion wird verwendet, um zu bestimmen, ob eine Zeichenfolge eine bestimmte Teilzeichenfolge enthält.

fn:contains()-Funktionssyntax:

Syntax

<c:if test="${fn:contains(<Original-String>, <Zu Suchender-Teilstring>)}">
...
</c:if>

Beispiel-Demonstration

Nachfolgender Beispiel zeigt die Funktion dieses Funktons:

<%@ 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>Verwenden Sie JSTL-Funktionen</title>
</head>
<body>
<c:set var="theString" value="I am from w3codebox"/>
<c:if test="${fn:contains(theString, 'w3codebox')}>
   <p>Finden w3codebox<p>
</c:if>
<c:if test="${fn:contains(theString, 'w3codebox')}>
   <p>Finden w3codebox<p>
</c:if>
</body>
</html>

Die Ergebnisse des Laufs sind wie folgt:

Finden w3codebox

JSP-Standard-Tag-Bibliothek