aspx中:

<table>
                <tr>
                    <td style="width: 178px" colspan="4">
                    <asp:Label ></asp:Label></td>
                   
                </tr>
            </table>

aspx.cs中:
 public static Regex RX = new Regex(@"^-?[1-9]\d*|[[\u4e00-\u9fa5]+]$",RegexOptions.IgnoreCase);
  protected void btnSubmit_Click(object sender, System.EventArgs e)
  {
            this.lblMessage.Text = "";
            string str = this.txtString.Text;
            if (RX.IsMatch(str))
            {
                int indexBegin = str.IndexOf("[");
                int indexEnd = str.LastIndexOf("]");
                string endstr = str.Substring(indexBegin + 1, indexEnd - indexBegin - 1);//截取“[ ]”里的文本
                Regex Rx = new Regex(@"[\u4e00-\u9fa5]+", RegexOptions.IgnoreCase);
                String resultStr = "<font color=red>" + endstr + "</font>";
                string ResultAll = Rx.Replace(endstr, resultStr);
                // lblMessage.Text = ResultAll;
                Regex Rex = new Regex(@"[[\u4e00-\u9fa5]+]");
                this.lblMessage.Text = Rex.Replace(str, "[" + ResultAll + "]");
            }
            else
            {
                //return;
                lblMessage.Text = str;
            }
  }

相关文章: