Ramesh Kotha
Ramesh Kotha

Reputation: 8322

How to format string in JSTL core tags?

I am using JSP EL. I have a string like "Village Green,Colgate University,Hamilton,NY". I want to show only Village Green. How can I do this?

<c:forEach items="${listOfSources}" var = "source">
    <option value="${source }" >${source }</option>
</c:forEach>

The option value should be the whole string, but I want to show only Village Green to select. How can I achieve this?

Upvotes: 0

Views: 4130

Answers (1)

Jigar Joshi
Jigar Joshi

Reputation: 240946

Use just substringBefore from JSTL assuming that you need String from0 to first ,


Code Snippet:

<c:out value="${fn:substringBefore(source,',')}"/>

Document :

Upvotes: 2

Related Questions