C#字符串操作类StringHelper源码.docx

上传人:b****7 文档编号:8951702 上传时间:2023-02-02 格式:DOCX 页数:15 大小:18.63KB
下载 相关 举报
C#字符串操作类StringHelper源码.docx_第1页
第1页 / 共15页
C#字符串操作类StringHelper源码.docx_第2页
第2页 / 共15页
C#字符串操作类StringHelper源码.docx_第3页
第3页 / 共15页
C#字符串操作类StringHelper源码.docx_第4页
第4页 / 共15页
C#字符串操作类StringHelper源码.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

C#字符串操作类StringHelper源码.docx

《C#字符串操作类StringHelper源码.docx》由会员分享,可在线阅读,更多相关《C#字符串操作类StringHelper源码.docx(15页珍藏版)》请在冰豆网上搜索。

C#字符串操作类StringHelper源码.docx

C#字符串操作类StringHelper源码

.NET字符串操作类StringHelper(C#版)

using System;   

using System.Collections.Generic;   

using System.Linq;   

using System.Text;   

using System.Text.RegularExpressions;   

  

namespace Common   

{   

    /// 

   

    /// 字符串操作类   

    /// 

   

    public class StringHelper   

    {   

        public StringHelper()   

        {   

  

        }   

  

        /// 

   

        /// 出错时弹出提示对话框   

        /// 

   

        /// 检验控件id值   

        /// 表单id值   

        /// 提示信息   

        /// string   

        public static string JsIsNull(string str_Control_Name, string str_Form_Name, string str_Prompt)   

        {   

            return  "alert('" + str_Prompt + "');document." + str_Form_Name + "." + str_Control_Name + ".focus(); document." + str_Form_Name + "." + str_Control_Name + ".select();";   

        }   

  

  

        /// 

   

        /// 出错时弹出提示对话框   

        /// 

   

        /// 提示信息   

        /// string   

        public static string JsIsNull(string str_Prompt)   

        {   

            return  "alert('" + str_Prompt + "');";   

        }   

  

  

        /// 

   

        /// 关闭对话框   

        /// 

   

        /// 提示信息   

        /// string   

        public static string  CloseParent(string str_Prompt)   

        {   

            return  "alert('" + str_Prompt + "');window.parent.close();";   

        }   

  

        /// 

   

        /// 出错时弹出提示对话框--关闭窗口   

        /// 

   

        /// 提示信息   

        /// true为上个窗口自动刷新   

        /// string   

        public static string JsIsNull(string str_Prompt, bool isReLoad)   

        {   

            if (isReLoad)   

            {   

                return  "alert('" + str_Prompt + "');opener.window.document.location.reload();window.close();";   

            }   

            else  

            {   

                return  "alert('" + str_Prompt + "');window.close();";   

            }   

        }   

  

        /// 

   

        ///是否关闭窗口   

        /// 

   

        /// 提示信息   

        /// true为关闭   

        /// string   

        public static string  JsIsClose(string str_Prompt,  bool isClose)   

        {   

            if (!

isClose)   

            {   

                return  "alert('" + str_Prompt + "');";   

            }   

            else  

            {   

                return  "alert('" + str_Prompt + "');window.close();opener.window.document.location.reload();";   

            }   

        }   

  

        /// 

   

        /// 弹出信息并重装窗口   

        /// 

   

        /// 提示信息   

        /// 重装路径   

        /// string   

        public static string  JsIsReLoad(string str_Prompt, string reLoadPath)   

        {   

            return  "alert('" + str_Prompt + "');this.window.document.location.reload('" + reLoadPath + "');";   

        }   

  

        /// 

   

        /// 重装窗口   

        /// 

   

        /// 提示信息   

        /// string   

        public static string  JsIsReLoad(string reLoadPath)   

        {   

            return  "this.window.document.location.reload('" + reLoadPath + "');";   

        }   

  

        /// 

   

        /// 获得一个16位时间随机数   

        /// 

   

        /// 返回随机数   

        public static string GetDataRandom()   

        {   

            string strData = DateTime.Now.ToString();   

            strData = strData.Replace(":

", "");   

            strData = strData.Replace("-", "");   

            strData = strData.Replace(" ", "");   

            Random r = new Random();   

            strData = strData + r.Next(100000);   

            return strData;   

        }   

  

        /// 

   

        ///  获得某个字符串在另个字符串中出现的次数   

        /// 

   

        /// 要处理的字符   

        /// 符号   

        /// 返回值   

        public static int GetStrCount(string strOriginal, string strSymbol)   

        {   

            int count = 0;   

            for (int i = 0; i < (strOriginal.Length - strSymbol.Length + 1); i++)   

            {   

                if (strOriginal.Substring(i, strSymbol.Length) == strSymbol)   

                {   

                    count = count + 1;   

                }   

            }   

            return count;   

        }   

  

        /// 

   

        /// 获得某个字符串在另个字符串第一次出现时前面所有字符   

        /// 

   

        /// 要处理的字符   

        /// 符号   

        /// 返回值   

        public static string GetFirstStr(string strOriginal, string strSymbol)   

        {   

            int strPlace = strOriginal.IndexOf(strSymbol);   

            if (strPlace !

= -1)   

                strOriginal = strOriginal.Substring(0, strPlace);   

            return strOriginal;   

        }   

  

        /// 

   

        /// 获得某个字符串在另个字符串最后一次出现时后面所有字符   

        /// 

   

        /// 要处理的字符   

        /// 符号   

        /// 返回值   

        public static string GetLastStr(string strOriginal, string strSymbol)   

        {   

            int strPlace = strOriginal.LastIndexOf(strSymbol) + strSymbol.Length;   

            strOriginal = strOriginal.Substring(strPlace);   

            return strOriginal;   

        }   

  

        /// 

   

        /// 获得两个字符之间第一次出现时前面所有字符   

        /// 

   

        /// 要处理的字符   

        /// 最前哪个字符   

        /// 最后哪个字符   

        /// 返回值   

        public static string GetTwoMiddleFirstStr(string strOriginal, string strFirst, string strLast)   

        {   

            strOriginal = GetFirstStr(strOriginal, strLast);   

            strOriginal = GetLastStr(strOriginal, strFirst);   

            return strOriginal;   

        }   

  

        /// 

   

        ///  获得两个字符之间最后一次出现时的所有字符   

        /// 

   

        /// 要处理的字符   

        /// 最前哪个字符   

        /// 最后哪个字符   

        /// 返回值   

        public static string GetTwoMiddleLastStr(string strOriginal, string strFirst, string strLast)   

        {   

            strOriginal = GetLastStr(strOriginal, strFirst);   

            strOriginal = GetFirstStr(strOriginal, strLast);   

            return strOriginal;   

        }   

  

        /// 

   

        /// 从数据库表读记录时,能正常显示   

        /// 

   

        /// 要处理的字符   

        /// 返回正常值   

        public static string GetHtmlFormat(string strContent)   

        {   

            strContent = strContent.Trim();   

  

            if (strContent == null)   

            {   

                return "";   

            }   

            strContent = strContent.Replace("<", "<");   

            strContent = strContent.Replace(">", ">");   

            strContent = strContent.Replace("\n", "");   

            return (strContent);   

        }   

  

        /// 

   

        /// 检查相等之后,获得字符串   

        /// 

   

        /// 字符串1   

        /// 字符串2   

        /// 相等之后要返回的字符串   

        /// 返回字符串   

        public static string GetCheckStr(string str, string checkStr, string reStr)   

        {   

            if (str == checkStr)   

            {   

                return reStr;   

            }   

            return "";   

        }   

  

        /// 

   

        /// 检查相等之后,获得字符串   

        /// 

   

        /// 数值1   

        /// 数值2   

        /// 相等之后要返回的字符串   

        /// 返回字符串   

        public static string GetCheckStr(int str, int checkStr, string reStr)   

        {   

            if (str == checkStr)   

            {   

                return reStr;   

            }   

            return "";   

        }   

        /// 

   

        /// 检查相等之后,获得字符串   

        /// 

   

        ///    

        ///    

        ///    

        ///    

        public static string GetCheckStr(bool str, bool checkStr, string reStr)   

        {   

            if (str == checkStr)   

            {   

                return reStr;   

            }   

            return "";   

        }   

        /// <

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 科学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1