これには主に、サイト ユーザー IP の取得、文字列の最後の「,」記号の削除、文字列の最初の「/」記号の削除などが含まれます。/// <summary>
/// サイトユーザーのIPを取得する
/// </概要>
/// <戻り値></戻り値>
パブリック静的文字列 getUserIP()
{
return HttpContext.Current.Request.ServerVariables[REMOTE_ADDR].ToString();
}
/// <概要>
/// 文字列から最後の「,」記号を削除します
/// </概要>
/// <param name=chr>: 処理対象の文字列</param>
/// <returns>処理された文字列を返します</returns>
パブリック静的文字列 Lost(string chr)
{
if (chr == null || chr == string.Empty)
{
戻る ;
}
それ以外
{
chr = chr.Remove(chr.LastIndexOf(,));
chrを返します。
}
}
/// <概要>
/// 文字列から最初の「/」記号を削除します
/// </概要>
/// <param name=chr>処理対象の文字列</param>
/// <returns>処理された文字列を返します</returns>
パブリック静的文字列 Lostfirst(string chr)
{
文字列 flg = ;
if (chr != string.Empty || chr != null)
{
if (chr.Substring(0, 1) == /)
flg = chr.Replace(chr.Substring(0, 1), );
それ以外
flg = chr;
}
戻りフラグ;
}
/// <概要>
/// HTML 内の特殊文字を置換します。
/// </概要>
/// <param name=theString>置換する必要があるテキスト。 </param>
/// <returns>置換されたテキスト。 </戻り>
パブリック静的文字列 HtmlEncode(string theString)
{
theString = theString.Replace(>, >);
theString = theString.Replace(<, <);
theString = theString.Replace( , );
theString = theString.Replace( , );
theString = theString.Replace(/, );
theString = theString.Replace(/', ');
theString = theString.Replace(/n, <br/> );
文字列を返します。
}
/// <概要>
/// HTML 内の特殊文字を復元する
/// </概要>
/// <param name=theString>復元する必要があるテキスト。 </param>
/// <returns>復元されたテキスト。 </戻り>
public static string HtmlDiscode(string theString)
{
theString = theString.Replace(>, >);
theString = theString.Replace(<, <);
theString = theString.Replace( , );
theString = theString.Replace( , );
theString = theString.Replace(, /);
theString = theString.Replace(', /');
theString = theString.Replace(<br/> , /n);
文字列を返します。
}
/// <概要>
/// 乱数を生成する
/// </概要>
/// <param name=length>長さを生成</param>
/// <戻り値></戻り値>
public static string Number(int Length)
{
戻り値 Number(長さ, false);
}
/// <概要>
/// 乱数を生成する
/// </概要>
/// <param name=Length>長さを生成</param>
/// <param name=Sleep>重複を避けるために生成前に現在のスレッドをブロックするかどうか</param>
/// <戻り値></戻り値>
public static string Number(int Length, bool Sleep)
{
もし(眠る)
System.Threading.Thread.Sleep(3);
文字列結果 = ;
System.Random ランダム = new Random();
for (int i = 0; i < 長さ; i++)
{
結果 += ランダム.Next(10).ToString();
}
結果を返します。
}
これには主に、サイト ユーザー IP の取得、文字列の最後の「,」記号の削除、文字列の最初の「/」記号の削除などが含まれます。
//ポップアップダイアログボックス
public static void salert(string str)
{
HttpContext.Current.Response.Write(<script>alert(' + str + ');</script>);
}
/// <概要>
/// メッセージプロンプトボックスを表示し、前のページに戻ります
/// </概要>
/// <param name=page>現在のページ ポインター、通常はこれ</param>
/// <param name=strMsg>プロンプトメッセージ</param>
public static void ShowGoHistory(System.Web.UI.Page ページ、文字列 strMsg)
{
page.ClientScript.RegisterStartupScript(page.GetType(), message, <script language='javascript' defer>alert(' + strMsg.ToString() + ');window.history.go(-1);</script> );
}
/// <概要>
/// メッセージプロンプトダイアログボックスを表示し、ページにジャンプします
/// </概要>
/// <param name=page>現在のページ ポインター、通常はこれ</param>
/// <param name=strMsg>プロンプトメッセージ</param>
/// <param name=url> ジャンプ先の URL</param>
public static void ShowRedirect(System.Web.UI.Page ページ、文字列 strMsg、文字列 URL)
{
StringBuilder ビルダー = new StringBuilder();
Builder.Append(<script language='javascript' defer>);
Builder.AppendFormat(alert('{0}');, strMsg);
Builder.AppendFormat(top.location.href='{0}', url);
Builder.Append(</script>);
page.ClientScript.RegisterStartupScript(page.GetType(), メッセージ, Builder.ToString());
}
//一重引用符を挿入するには
パブリック静的文字列delSingle(string str)
{
return str.Replace(', '');
}
//gridviw で Excel にエクスポート
public static void ToExcel(System.Web.UI.Control ctl)
{
HttpContext.Current.Response.AppendHeader(Content-Disposition,attachment;filename=Excel.xls);
HttpContext.Current.Response.Charset = UTF-8;
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = application/ms-excel;//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = 新しい System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = 新しい System.Web.UI.HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
///System.Security.Cryptography を使用します。
///System.Text を使用します。
/// <概要>
/// MD5関数
/// </概要>
/// <param name=str>元の文字列</param>
/// <returns>MD5 結果</returns>
パブリック静的文字列 MD5(文字列 str)
{
byte[] b = Encoding.Default.GetBytes(str);
b = 新しい MD5CryptoServiceProvider().ComputeHash(b);
文字列 ret = ;
for (int i = 0; i < b.Length; i++)
ret += b[i].ToString(x).PadLeft(2, '0');
retを返します。
}
///System.Net を使用します。
///System.IO を使用します。
/// <概要>
/// URL に基づいてソース ファイルの内容を取得します
/// </概要>
/// <param name=url>有効な URL アドレス</param>
/// <戻り値></戻り値>
パブリック静的文字列 GetSourceTextByUrl(文字列 URL)
{
WebRequest リクエスト = WebRequest.Create(url);
request.Timeout = 20000;//20 秒のタイムアウト
WebResponse 応答 = request.GetResponse();
ストリーム resStream = 応答.GetResponseStream();
StreamReader sr = 新しい StreamReader(resStream);
戻り sr.ReadToEnd();
}