Java jstl function substringbefore
The fn:substringBefore
function is a JSTL function that returns a substring of the input string that precedes the first occurrence of a specified delimiter. The function takes two arguments: the input string and the delimiter.
The syntax of the fn:substringBefore
function is as follows:
${fn:substringBefore(string, delimiter)}
where string
is the input string and delimiter
is the delimiter to search for.
For example, the following expression returns the substring that precedes the first occurrence of the delimiter "," in the input string "hello, world":
${fn:substringBefore("hello, world", ",")}
This expression returns the string "hello".
You can also use variables instead of literals for the arguments. For example, if you have a variable text
containing a string and a variable delimiter
containing the delimiter to search for, you can get the substring using the following expression:
${fn:substringBefore(text, delimiter)}
This expression returns the substring of the string stored in the text
variable that precedes the first occurrence of the delimiter stored in the delimiter
variable.
Note that the fn
tag library must be imported at the beginning of the JSP page using the following tag:
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>