English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The fn:startsWith() function is used to determine if a string starts with a specified prefix.
The syntax of the fn:startsWith() function is as follows:
<c:if test="${fn:startsWith(<originalString>, <searchPrefix>)}"> ... </c:if>
The following example demonstrates the function's functionality:
<%@ 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> <c:set var="string" value="w3codebox: I am from w3codebox./> <c:if test="${fn:startsWith(string, 'Google')"> <p>String starts with Google/p> </c:if> <br /> <c:if test="${fn:startsWith(string, 'w"3codebox')}> <p>String starts with w3codebox beginning</p> </c:if> </body> </html>
The running result is as follows:
String starts with w3codebox beginning