字串控制類

來源:互聯網
上載者:User

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
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.