如何在 JSP 中检查指定子字符串在字符串中索引?
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP