字符串控制类

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Xml;
using System.Drawing;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Security.Cryptography;

namespace ClassLibrary
{
    #region 字符串控制类
    /// <summary>
    /// 字符串控制类
    /// </summary>
    public static class ControlString
    {
        #region 提示消息函数

        #region 显示提示消息
        /// <summary>
        /// 显示提示消息
        /// </summary>
        /// <param name="str_Message">要显示得数据</param>
        /// <param name="page">页面类</param>
        public static void ShowMessageBox(string str_Message, Page page)
        {
            Type cstype = page.GetType();
            ClientScriptManager cs = page.ClientScript;
            cs.RegisterStartupScript(cstype, "", "alert('" + str_Message + "');", true);

        }
        #endregion

        #region 显示消息并导向到目标页面
        /// <summary>
        /// 显示消息并导向到目标页面
        /// </summary>
        /// <param name="str_Message">显示数据</param>
        /// <param name="url">目标路径</param>
        /// <param name="page">页面类</param>
        public static void ShowMessageBoxRedirect(string str_Message, string url, Page page)
        {
            Type cstype = page.GetType();
            ClientScriptManager cs = page.ClientScript;
            cs.RegisterStartupScript(cstype, "", "alert('" + str_Message + "');window.location.href='" + url + "';", true);
        }
        #endregion

        #region 显示信息并关闭本窗口
        /// <summary>
        /// 显示信息并关闭本窗口
        /// </summary>
        /// <param name="str_Message">显示数据</param>
        /// <param name="page">页面类</param>
        public static void ShowMessageBoxAndCloseWindow(string str_Message, Page page)
        {
            Type cstype = page.GetType();
            ClientScriptManager cs = page.ClientScript;
            cs.RegisterStartupScript(cstype, "", "alert('" + str_Message + "');window.close();", true);
        }
        #endregion

        #region 显示信息窗口并后退一步
        /// <summary>
        /// 显示信息窗口并后退一步
        /// </summary>
        /// <param name="str_Message">显示数据</param>
        /// <param name="page">页面类</param>
        public static void ShowMessageBoxGoBack(string str_Message, Page page)
        {
            Type cstype = page.GetType();
            ClientScriptManager cs = page.ClientScript;
            cs.RegisterStartupScript(cstype, "", "alert('" + str_Message + "');window.history.go(-1);", true);
        }
        #endregion

        #endregion       

        #region 获取长度函数

        #region 获取指定长度字符串
        /// <summary>
        /// 获取指定长度字符串
        /// </summary>
        /// <param name="Str">原始数据</param>
        /// <param name="Count">获取长度</param>
        /// <returns>返回数据</returns>
        public static string GetLimitStr(string Str, int Count)
        {
            if (Str.Length > Count)
                Str = Str.Substring(0, Count);
            return Str;
        }
        #endregion

        #region 获取前N个字符串
        /// <summary>
        /// 获取前N个字符串
        /// </summary>
        /// <param name="Str">原始数据</param>
        /// <param name="N">指定长度</param>
        /// <returns>返回数据</returns>
        public static string GetNstring(string Str, int N)
        {
            int intn = N;
            if (intn < 1) { intn = 1; }

            string tmpstr = Str;
            Char[] cc = tmpstr.ToCharArray();
            int intLen = tmpstr.Length;
            int i;
            for (i = 0; i < cc.Length; i++)
            {
                if (System.Convert.ToInt32(cc[i]) > 255 || (System.Convert.ToInt32(cc[i]) > 64 && System.Convert.ToInt32(cc[i]) < 91))
                {
                    intLen++;
                }
            }
            if (intLen > N)
            {
                tmpstr = tmpstr.Substring(0, tmpstr.Length - 1);
                tmpstr = GetNstring(tmpstr, intn);
            }

            return tmpstr;
        }
        #endregion

        #endregion
    }
    #endregion
}

posted @ 2007-05-30 12:29  世之云枭  阅读(206)  评论(0编辑  收藏  举报