如何更改字符串中特定单词的颜色? vb.net

时间:2016-11-18 13:40:04

标签: asp.net vb.net

我的字符串中特定单词的颜色有问题。 我有这样的字符串:

1)我创建一个这样的表:

Dim SequenceTable As New DataTable
SequenceTable.Columns.Add("Paragraph", GetType(String))
SequenceTable.Columns.Add("Description", GetType(String))
SequenceTable.Columns.Add("ActivityName", GetType(String))

2)我得到值Paragraph,Description和activityName:

If SequenceRow.IsNull("ActivityNumber") = False Then
                                ActivityNumber = SequenceRow.ActivityNumber
                            End If

                            If SequenceRow.IsNull("Specification") = False Then
                                Specification = SequenceRow.Specification
                            End If

                            If SequenceRow.IsNull("Dimension") = False Then
                                Paragraph = SequenceRow.Dimension
                            End If

3)我把所有字符串放在表格中:

                    Cell = New TableCell
                    Cell.HorizontalAlign = HorizontalAlign.Left
                    Cell.Width = Unit.Percentage(16.5)
                    Cell.CssClass = "FormatTabel"
                    Cell.Text = Description
                    Cell.Font.Size = 6
                    Cell.Wrap = True
                    Row.Cells.Add(Cell)

我在描述中的字符串

Description = "Presence and pictures required. Raw data and multiload required. "

我希望单词图片为红色,所有单词都为黑色?但是如何为单词“pictures”设置红色并放入表格后?

由于

2 个答案:

答案 0 :(得分:3)

您可以在单元格中使用 @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (convertView == null) { view = LayoutInflater.from(context).inflate(layoutResource, parent, false); } Match programItem = getItem(position); ImageView ourTeamLogo = (ImageView) view.findViewById(R.id.program_item_our_team_logo); ImageView foeLogo = (ImageView) view.findViewById(R.id.program_item_foe_logo); if (programItem.isHome()) { ourTeamLogo.setImageResource(R.drawable.our_team_logo); Picasso.with(context). cancelRequest(foeLogo); Picasso.with(getContext()) .load(programItem.getFoeLogoURL()) .fit().placeholder(R.drawable.placeholder_team).into(foeLogo); } else { foeLogo.setImageResource(R.drawable.our_team_logo); Picasso.with(context). cancelRequest(ourTeamLogo); Picasso.with(getContext()) .load(programItem.getFoeLogoURL()) .fit().placeholder(R.drawable.placeholder_team).into(ourTeamLogo); } return view; } 添加带有格式化文字的<span/>,而不是InnerHtml

Text

答案 1 :(得分:0)

string AddColor(string Text, string word string color)
{
    return Text.Replace(word, "<span color: '" + color + "'>"+word+"</span>")
}