
<%...@ Page Language="C#" AutoEventWireup="true" CodeFile="BlackWord.aspx.cs" Inherits="BlackWord" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>BlackWord</title>
</head>
<body>
<form id="form1" runat="server">
<h2>
BlackWord画面実現方法
</h2>
<div>
<asp:TextBox ID="TextBox1" runat="server" Height="100px" TextMode="MultiLine" Width="240px"></asp:TextBox>
</div>
<asp:Button ID="btnBlackWord" runat="server" OnClick="btnBlackWord_Click" Text="BlackWord" />
<asp:Panel ID="Panel1" runat="server" Height="100px" Width="240px" Wrap="true" ScrollBars="Vertical"
Style="word-wrap: break-word">
<%=strBlogText %>
</asp:Panel>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
public partial class BlackWord : System.Web.UI.Page
...{
// 日記本文
public string strBlogText = string.Empty;
// BlackWord
public static string[] strBlackWord = new string[2] ...{"kill","fuck"} ;
protected void Page_Load(object sender, EventArgs e)
...{
}
protected void btnBlackWord_Click(object sender, EventArgs e)
...{
// 変数の定義
string strEvaluator1 = "<span style=" + """ + "background-color: green" + """ + ">";
string strEvaluator2 = "</span>";
// 日記本文の取得
strBlogText = TextBox1.Text;
// BlackWordの捜索
for (int i = 0; i < 2; i++)
...{
strBlogText = Regex.Replace(
strBlogText,
strBlackWord[i],
strEvaluator1 + strBlackWord[i] + strEvaluator2,
RegexOptions.IgnoreCase
);
}
}
}
参考:http://www.phpx.com/man/dhtmlcn/objects/SPAN.html
发表于 @ 2007年11月08日 15:55:00 | 评论( loading... ) | 举报| 收藏