Skip to content

Files

Latest commit

5142ebd · Oct 15, 2019

History

History
43 lines (31 loc) · 1.54 KB

20.md

File metadata and controls

43 lines (31 loc) · 1.54 KB

fn:indexOf() - JSTL 函数

原文: https://beginnersbook.com/2013/12/fn-indexof-jstl-function/

fn:indexOf()函数用于查找提供的字符串中字符串的起始位置(索引)。

语法

int indexOf(String,  String )

此函数的返回类型为int。它返回第一个字符串(函数的第一个参数)中第二个字符串(函数的第二个参数)的起始位置(或索引)。

注意事项:

  • 当输入字符串中找不到字符串时,函数返回 -1
  • 功能区分大小写。它将同一字母表的大写和小写字符视为不同。
  • 它返回第一次出现的索引,这意味着如果字符串在输入中存在多于一次,则函数将返回第一次出现的索引。参考例子。

fn:indexOf()函数的示例

在这个例子中,我们找到几个字符串的索引并使用 EL 显示它们。

<%@ 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>JSTL fn:indexOf() example</title>
</head>
<body>
${fn:indexOf("My name is Chaitanya Singh", "chaitanya")}
${fn:indexOf("My name is Chaitanya Singh", "Chaitanya")}
${fn:indexOf("This is an example", "is")}
${fn:indexOf("JSTL function - indexOf function", "function")}
</body>
</html>

输出:

fn-indexOf-example