如何显示固定长度的内容?
我有一个像这样的字符串:
<p><strong>Make sure you’re paying the right price for your household and trade services with pricing calculators from Australia’s largest online services marketplace, ServiceSeeking.com.au </strong></p>.
我想用
显示该字符串的一部分(只有内容,没有 HTML 标记)。我尝试了 substring()
,但我不知道 html 标签在哪里完成,所以我的表单被破坏了。我只想得到大约 100 个字符。我该怎么做?
I have a string like this:
<p><strong>Make sure you’re paying the right price for your household and trade services with pricing calculators from Australia’s largest online services marketplace, ServiceSeeking.com.au </strong></p>.
I want to display a part of this string with <h:outputText escape="false">
(just content, no HTML tag). I tried substring()
, but I don't know where html tag finish, so my form is broken. I want to get about 100 character only. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否 100% 正确地理解了你的问题,但如果你要显示的所有字符串大致都是你的示例中的格式,那么你可以在没有 html 的情况下显示它们,并以这种方式缩短到 100 个字符:
这就是 bean :
其中 text 变量包含像示例中那样的字符串。
I'm not sure if I understood your question 100% correctly but if all the strings you are to display are roughtly in the format from your example then you may display them without html and shortened to 100 characters this way:
And this is the bean:
Where text variable contains string like in your example.
您可以使用以下 JSF HTML 标签输出文本:
You can output text with the following JSF HTML Tag: