如何高亮显示字符串中的某些词
大家好,我有一个小问题想请交各位大侠:
我有一个搜索页面,返回的结果是一大串字符串,我需要将关键词高亮显示出来。
比如说,我的输入字串是(我随便从cnn.com上取了一段做例子)以下一串字符,我的关键词是: Hampton, amendment , Heath
If lawmakers don't take action in the final weeks of the legislative session, the battle will move to the courthouse this spring, said state Rep. Tyrone Brooks, an Atlanta Democrat and civil rights activist leading the officers' campaign.
"I was hoping we wouldn't have to go this route, but litigation appears to be our only option," Brooks said.
Ronald Hampton, executive director of the National Black Police Association, said he knows of no other state with a similar pension situation. "Only Georgia is shameless enough to still have this out there," Hampton said.
The Georgia House has twice passed an amendment resolution but it has gone nowhere in the state Senate. An amendment requires a vote of two-thirds of each chamber as well as approval by voters.
"We can't fix everything for everybody," said state Sen. Bill Heath, chairman of the Senate Retirement Committee.
Heath, a Republican, argued that making retroactive changes to retirement benefits "opens up a can of worms and could destroy the pension system."
我想得到的字串是:
...Ronald Hampton, executive director of the National Black Police Association, said he knows of no other state with a similar pension situation. "Only Georgia is shameless enough to still have this out there," Hampton said. ...An amendment requires a vote of two-thirds of each chamber as well as approval by voters.....
"We can't fix everything for everybody," said state Sen. Bill Heath, chairman of the Senate Retirement Committee.
Heath, a Republican, argued that making retroactive....
各位请注意关键词可以有多个,输入的字串大小不一,最好是所有的关键词都给显示出来。那由于各个关键词在搜索结果中的距离会不一样,所以必须对间隔得远的关键词中间用省略号处理。例外就是最后的返回结果长度最好是可以自由设定,比如说这是一个method,那参数将会是:input, output, keyword[], length
不知各位谁能提供一些好的建议或者最好是有现成的代码,非常感谢。