简体   繁体   English

Thymeleaf - 如何删除字符串的最后一个字符

[英]Thymeleaf - How to remove the last character of a string

In the Thymeleaf template engine, how can I remove the last character of a String?在 Thymeleaf 模板引擎中,如何删除字符串的最后一个字符? For example, if I have the following expression:例如,如果我有以下表达式:

<td th:text="${person.someProperty}"></td>

How should I remove the last character of the ${person.someProperty} string, and let it only display the remaining string?我应该如何删除 ${person.someProperty} 字符串的最后一个字符,让它只显示剩余的字符串? I'm trying to use a combination of #strings.substring() and #strings.length(), but have not made it work yet.我正在尝试结合使用#strings.substring() 和#strings.length(),但还没有成功。 Thanks.谢谢。

You can use string function substring to remove last character in thymeleaf eg您可以使用字符串函数 substring 删除 thymeleaf 中的最后一个字符,例如

<td th:text="${#strings.substring(person.someProperty, 0, #strings.length(person.someProperty)-1)}"></td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM