比较和下划线问题
我有两个数组,一个是单词,另一个是句子。现在,我想强调这个常用词。例如,第一个单词是“at”,第一个句子是“dont at work”。所以我想显示单词和句子,但在句子中必须加下划线。怎么做这个。
I have two array one is words another is sentences. Now, i want to underline this common word. for examples first word is "at" and first sentences is "dont at work". so I want to to display both word and sentence but in sentence was must be underline. how to make this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需找到该单词在整个句子
String
中的第一个和最后一个单词位置,然后使用此代码在以下内容下划线:注意:在此示例中 4 和 6 是硬编码的,您可以找到 start通过对句子
String
使用一些循环和比较方法来确定终点You have just to find the word's first and last word place in whole sentence
String
, then use this code to underline that something like:NOTE: in this example 4 and 6 are hard coded, You can find start and end points by using some looping and comparing methods upon sentence
String
查看 SpannableString 和 UnderlineSpan。从您的句子中创建一个
SpannableString
,找到每个单词的开始和结束索引,并使用这些索引设置一个UnderlineSpan
。Look at SpannableString and UnderlineSpan. Create a
SpannableString
from your sentence, find the start and end index of each word, and set anUnderlineSpan
with those indexes.