当前位置: 代码迷 >> .NET Framework >> 标题的颜色如何读取?
  详细解决方案

标题的颜色如何读取?

热度:83   发布时间:2016-05-02 00:34:12.0
标题的颜色怎么读取????
C# code
比如数据库中有几条<font style="color:red">大个大法官大个大法官的风格的风格的风格的风格大法官!</font> <font style="color:yellow">大个大法大法官格的风格的风格大法官!</font> <font style="color:blue">大多个个大法官的风格的风格的风格的风格大法官!</font> <font style="color:red">大个大法官格大法官!</font> 我读取的时候,如果直接  public string getstr(string str)    {        if (str.Length>10)        {            return str.Substring(0,10) + "...";        }        else        {            return str;        }    }然后,使用repeater绑定<%#getstr(Eval("Title").ToString())%>这样的话,读取出来,就不显示文字的颜色,而且,字符也显示了,,,怎么搞???才能显示文字,而且文字要对应相对应的颜色???


------解决方案--------------------
C# code
            string s = "<font style=\"color:red\">大个大法官大个大法官的风格的风格的风格的风格大法官!</font>";            Regex regex=new Regex(@"^<font (.*?)[^>]>(.*?)[^<]</font>$",RegexOptions.IgnoreCase);            Match m = regex.Match(s);            if (m.Groups.Count > 0)            {                string str = m.Groups[2].Value;                if (str.Length > 10)                {                   str=str.Substring(0, 10) + "...";                }                str = "<font " + m.Groups[1].Value + "\">" + str + "</font>";            }
------解决方案--------------------
建立一个txt,内容
HTML code
<font style="color:red">大个大法官大个大法官的风格的风格的风格的风格大法官!</font> <font style="color:red">大个大法大法官格的风格的风格大法官!</font> <font style="color:red">大多个个大法官的风格的风格的风格的风格大法官!</font> <font style="color:red">大个大法官格大法官!</font>
------解决方案--------------------
探讨

建立一个txt,内容
HTML code

<font style="color:red">大个大法官大个大法官的风格的风格的风格的风格大法官!</font>
<font style="color:red">大个大法大法官格的风格的风格大法官!</font>
<font style="color:red">大多个个大法官的风格的风格的风格的风格大法官!</font>
<font sty……

------解决方案--------------------

C# code
static void Main(string[] args)            {                string str = @"<font style=""color:red"">大个大法官大个大法官的风格的风格的风格的风格大法官!</font>";                Regex re = new Regex(@"(<font [^>]+>)([^<]+)(</font>)", RegexOptions.None);                               Match ma = re.Match(str);                //string str = getstr(                str = ma.Groups[1] + getstr(ma.Groups[2].Value) + ma.Groups[3].Value;                Console.WriteLine(str);                Console.ReadLine();                                                          }            public static string getstr(string str)            {                if (str.Length > 10)                {                    return str.Substring(0, 10) + "...";                }                else                {                    return str;                }            }//str结果:<font style="color:red">大个大法官大个大法官...</font>
  相关解决方案