国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

一些C#實用的方法匯總

2019-11-14 13:38:58
字體:
供稿:網(wǎng)友
/// <summary>    /// 過濾字符串方法,用于將單引號等特殊符號轉(zhuǎn)化成中文符號    /// </summary>    /// <param name="msg">要轉(zhuǎn)化的字符串</param>    public static string  FilterStr(string msg)     {        string result = "";              // msg = msg.Replace(",", ",");               //msg = msg.Replace("<", "<");        //msg = msg.Replace(">", ">");       // msg = msg.Replace("/n", "<br>");        // msg = msg.Replace("/"", """);        msg = msg.Trim();        msg = msg.Replace("'", "''");            result = msg;        return result;    }    public static void message(string meg)    {          }    public static string FilterStrHtml(string msg)    {        string result = "";                msg = msg.Replace("/'", "'");        //msg = msg.Replace(",", ",");        msg = msg.Replace("/n", "<br>");        result = msg;        return result;    }    public static string FilterStrnocode(string msg)    {        string result = "";        msg = msg.Replace("'", "/'");        msg = msg.Replace("<br>", "/n");        result = msg;        return result;    }    //彈出消息框    /// <summary>    /// 消息提示框    /// </summary>    /// <param name="msg">消息內(nèi)容</param>    public static void ShowMsgBox(string msg)     {       System.Web.HttpContext.Current.Response.Write("<scrjavascript>alert('" + msg + "')</script>");    }    /// <summary>    /// 截取字符串    /// </summary>    /// <param name="msg">原字符串</param>    /// <param name="lenth">要截取的長度</param>    /// <returns></returns>    public static string ReturnStr(string msg, int lenth)    {        string result = msg;        if (msg.Length > lenth)        {            result = result.Substring(0, lenth);        }        // http://www.survivalescaperooms.com/sosoft/        return result;    }    /// <summary>    ///     /// </summary>    /// <param name="sqlstr"></param>    /// <returns></returns>    /// <summary>    /// 剪切指定長度的字符串,并去掉HTML標(biāo)記    /// </summary>    /// <param name="strr">要剪切字符串的Object形式</param>    /// <param name="len">長度(中文長度為2)</param>    /// <returns></returns>    public static string CutStringX(object strr, int len)    {        string str = strr.ToString();        string strRet = "";        char CH;        int nLen = str.Length;        int nCutLen = 0;        int nPos = 0;        int bLeft = 0;        int nChinese = 0;        while (nPos < nLen && nCutLen < len)        {            CH = str[nPos];            nPos++;            if (CH == '<')            {                bLeft++;                continue;            }            if (CH == '>')            {                bLeft--;                continue;            }            if (nCutLen == 0 && CH.ToString() == " " && CH.ToString() == "/n")            {                continue;            }            if (bLeft == 0)            {                //是否為中文                if (IsChinese(CH))                {                    nCutLen += 2;                    nChinese++;                }                else                {                    nCutLen += 1;                }                strRet += CH;            }        }        strRet = strRet.Replace(" ", " ");        if (nPos < nLen)        {            strRet += "";           // strRet += "...";        }        return strRet;    }    //是否為中文    public static bool IsChinese(char ch)    {        ASCIIEncoding en = new ASCIIEncoding();        byte[] b = en.GetBytes(ch.ToString());        return (b[0] == 63);    }    //HTML標(biāo)記轉(zhuǎn)換    public static string HTMLEncode(string str)    {        str = str.Replace("<", "<");        str = str.Replace(">", ">");        str = str.Replace("/n", "<br/>");        return str;    }    /// <summary>    /// 把日期時間轉(zhuǎn)換為日期,去掉時間    /// </summary>    /// <param name="str">格式:YYYY-MM-DD HH:MM:SS</param>    /// <returns>返回日期 YYYY-MM-DD</returns>    public static string GetDate(string str)    {        string[] s = str.Split(' ');        string[] ss = s[0].Split('-');        if (ss[1].Length < 2)            ss[1] = "0" + ss[1];        if (ss[2].Length < 2)            ss[2] = "0" + ss[2];        return ss[0] + "-" + ss[1] + "-" + ss[2];    } //隨機(jī)函數(shù)產(chǎn)生字符       public static string CreateRandomCode(int codeCount, string allChar)    {        //驗證碼中的出現(xiàn)的字符,避免了一些容易混淆的字符。         if (string.IsNullOrEmpty(allChar)) allChar = "3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,M,N,P,Q,R,S,T,U,W,X,Y";        string[] allCharArray = allChar.Split(',');        string randomCode = "";        int temp = -1;        bool breCreate = (codeCount < 6 && allCharArray.Length > 15);        Random rand = new Random();        for (int i = 0; i < codeCount; i++)        {            if (temp != -1)            {                rand = new Random(i * temp * ((int)DateTime.Now.Ticks));            }            int t = rand.Next(allCharArray.Length);            if (temp == t && breCreate)            {                return CreateRandomCode(codeCount, allChar);            }            temp = t;            randomCode += allCharArray[t];        }        return randomCode;    }

  


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 张家口市| 石狮市| 朔州市| 岳西县| 叶城县| 孟津县| 元阳县| 孙吴县| 景谷| 云浮市| 安康市| 大悟县| 磐安县| 建德市| 龙山县| 山丹县| 房山区| 郴州市| 万州区| 盐津县| 红安县| 长乐市| 卫辉市| 黄石市| 昭觉县| 汉沽区| 天津市| 邮箱| 申扎县| 洛川县| 蒙山县| 禹城市| 奈曼旗| 渝中区| 香格里拉县| 元氏县| 盖州市| 右玉县| 兴仁县| 延川县| 景德镇市|