Beispiel #1
0
 /// <summary>
 /// 差异日期天数
 /// </summary>
 /// <param name="oneDateTime">时间字符串</param>
 /// <returns></returns>
 public static int DiffDateDays(string oneDateTime)
 {
     if (string.IsNullOrEmpty(oneDateTime))
     {
         return(0);
     }
     return(TextUtility.DiffDateDays(DateTime.Parse(oneDateTime)));
 }
Beispiel #2
0
 /// <summary>
 /// 切割字符串加上延长符号
 /// </summary>
 /// <param name="originalVal">字符串</param>
 /// <param name="cutLength">去掉几位</param>
 /// <param name="prolongSymbol">延长符号</param>
 /// <returns></returns>
 public static string CutStringProlongSymbol(string originalVal, int cutLength, string prolongSymbol)
 {
     if (string.IsNullOrEmpty(prolongSymbol))
     {
         prolongSymbol = TextUtility.PROLONG_SYMBOL;
     }
     return(TextUtility.CutLeft(originalVal, cutLength) + prolongSymbol);
 }
Beispiel #3
0
 /// <summary>
 /// 切割字符串
 /// </summary>
 /// <param name="originalVal">字符串</param>
 /// <param name="cutLength">去掉几位</param>
 /// <returns></returns>
 public static string CutStringProlongSymbol(string originalVal, int cutLength)
 {
     if (originalVal.Length <= cutLength)
     {
         return(originalVal);
     }
     return(TextUtility.CutLeft(originalVal, cutLength) + TextUtility.PROLONG_SYMBOL);
 }
Beispiel #4
0
 /// <summary>
 /// JavaScript编码
 /// </summary>
 /// <param name="obj">原始字符串</param>
 /// <returns></returns>
 public static string JavaScriptEncode(object obj)
 {
     if (obj == null)
     {
         return(string.Empty);
     }
     return(TextUtility.JavaScriptEncode(obj.ToString()));
 }
Beispiel #5
0
 /// <summary>
 /// 获取当前日期时间长字符串
 /// </summary>
 /// <param name="prefix">前缀</param>
 /// <returns></returns>
 public static string GetDateTimeLongString(string prefix)
 {
     if (string.IsNullOrEmpty(prefix))
     {
         prefix = string.Empty;
     }
     return(prefix + TextUtility.GetDateTimeLongString());
 }
Beispiel #6
0
        /// <summary>
        /// 创建随机数
        /// </summary>
        /// <param name="len">长度</param>
        /// <returns></returns>
        public static string CreateRandomNum2(int len)
        {
            StringBuilder stringBuilder = new StringBuilder();
            Random        random        = new Random(TextUtility.GetNewSeed());

            for (int i = 0; i < len; i++)
            {
                int num = random.Next();
                stringBuilder.Append((char)(48 + (ushort)(num % 10)));
            }
            return(stringBuilder.ToString());
        }
Beispiel #7
0
 /// <summary>
 /// 验证一个字符串数组里面是否包含一个字符串
 /// </summary>
 /// <param name="matchStr">一个字符串</param>
 /// <param name="originalStr">分割字符</param>
 /// <param name="separator">可以被分割字符分割的字符串</param>
 /// <returns>返回状态</returns>
 public static bool InArray(string matchStr, string originalStr, string separator)
 {
     string[] array = TextUtility.SplitStrArray(originalStr, separator);
     for (int i = 0; i < array.Length; i++)
     {
         if (matchStr == array[i])
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #8
0
        /// <summary>
        /// 电子邮件编码
        /// </summary>
        /// <param name="originalStr">电子邮件字符串</param>
        /// <returns></returns>
        public static string EmailEncode(string originalStr)
        {
            string text = TextUtility.TextEncode(originalStr).Replace("@", "&#64;").Replace(".", "&#46;");

            return(TextUtility.JoinString("<a href='mailto:", new string[]
            {
                text,
                "'>",
                text,
                "</a>"
            }));
        }
Beispiel #9
0
        /// <summary>
        /// 创建身份验证的秘钥
        /// </summary>
        /// <param name="len">长度</param>
        /// <param name="onlyNum">复杂强度</param>
        /// <returns></returns>
        public static string CreateAuthStr(int len, bool onlyNum)
        {
            if (!onlyNum)
            {
                return(TextUtility.CreateAuthStr(len));
            }
            StringBuilder stringBuilder = new StringBuilder();
            Random        random        = new Random();

            for (int i = 0; i < len; i++)
            {
                int num = random.Next();
                stringBuilder.Append((char)(48 + (ushort)(num % 10)));
            }
            return(stringBuilder.ToString());
        }
Beispiel #10
0
        /// <summary>
        /// 根据当前输入的相对于项目的路径返回绝对路径
        /// </summary>
        /// <param name="strPath">相对路径</param>
        /// <returns></returns>
        public static string GetFullPath(string strPath)
        {
            string text = TextUtility.AddLast(AppDomain.CurrentDomain.BaseDirectory, "\\");

            if (strPath.IndexOf(":") < 0)
            {
                string text2 = strPath.Replace("..\\", "");
                if (text2 != strPath)
                {
                    int num = (strPath.Length - text2.Length) / "..\\".Length + 1;
                    for (int i = 0; i < num; i++)
                    {
                        text = text.Substring(0, text.LastIndexOf("\\"));
                    }
                    text2 = "\\" + text2;
                }
                strPath = text + text2;
            }
            return(strPath);
        }
Beispiel #11
0
        ///// <summary>
        ///// 跳转页面 (重定向)
        ///// </summary>
        ///// <param name="url">访问的网址</param>
        //public static void Redirect(string url)
        //{
        //	if (HttpContext.Current != null && !string.IsNullOrEmpty(url))
        //	{
        //		HttpContext.Current.Response.Redirect(url);
        //		HttpContext.Current.Response.StatusCode = 301;
        //		HttpContext.Current.Response.End();
        //	}
        //}

        ///// <summary>
        ///// 输出要下载的文件
        ///// </summary>
        ///// <param name="filepath">下载文件的路径</param>
        ///// <param name="filename">下载文件的名称</param>
        ///// <param name="filetype">设置输出流的 HTTP MIME 类型。</param>
        //public static void ResponseFile(string filepath, string filename, string filetype)
        //{
        //	if (HttpContextExtension.Current != null)
        //	{
        //		Stream stream = null;
        //		byte[] buffer = new byte[10000];
        //		try
        //		{
        //			stream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        //			long num = stream.Length;
        //			HttpContextExtension.Current.Response.ContentType = filetype;
        //			HttpContextExtension.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + Utility.UrlEncode(filename.Trim()).Replace("+", " "));
        //			while (num > 0L)
        //			{
        //				if (HttpContextExtension.Current.Response.IsClientConnected)
        //				{
        //					int num2 = stream.Read(buffer, 0, 10000);
        //					HttpContextExtension.Current.Response.OutputStream.Write(buffer, 0, num2);
        //					HttpContextExtension.Current.Response.Flush();
        //					buffer = new byte[10000];
        //					num -= (long)num2;
        //				}
        //				else
        //				{
        //					num = -1L;
        //				}
        //			}
        //		}
        //		catch (Exception ex)
        //		{
        //			HttpContextExtension.Current.Response.Write("Error : " + ex.Message);
        //		}
        //		finally
        //		{
        //			if (stream != null)
        //			{
        //				stream.Close();
        //			}
        //		}
        //		HttpContextExtension.Current.Response.End();
        //	}
        //}

        /// <summary>
        /// 查找指定目录下的所有.htm后缀的文件并返回字符串编码是UTF-8的文件路径
        /// </summary>
        /// <param name="directory">指定的目录,绝对路径</param>
        /// <returns>返回是UTF-8格式的.htm路径</returns>
        public static string[] SearchUTF8File(string directory)
        {
            StringBuilder stringBuilder = new StringBuilder();

            FileInfo[] files = new DirectoryInfo(directory).GetFiles();
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Extension.ToLower().Equals(".htm"))
                {
                    FileStream fileStream = new FileStream(files[i].FullName, FileMode.Open, FileAccess.Read);
                    bool       flag       = Utility.IsUTF8(fileStream);
                    fileStream.Close();
                    if (!flag)
                    {
                        stringBuilder.Append(files[i].FullName);
                        stringBuilder.Append("\r\n");
                    }
                }
            }
            return(TextUtility.SplitStrArray(stringBuilder.ToString(), "\r\n"));
        }
Beispiel #12
0
 /// <summary>
 /// 等同于Join方法,就是增加了验证
 /// </summary>
 /// <param name="separator"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static string Join(string separator, params string[] value)
 {
     return(TextUtility.JoinString(separator, value));
 }
Beispiel #13
0
 /// <summary>
 /// 等同于Join方法,就是增加了验证
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static string JoinString(params string[] value)
 {
     return(TextUtility.JoinString(string.Empty, value));
 }
Beispiel #14
0
 /// <summary>
 /// 减少字符串数量
 /// </summary>
 /// <param name="originalVal">字符串</param>
 /// <param name="startIndex">从第几位开始</param>
 /// <returns></returns>
 public static string CutString(string originalVal, int startIndex)
 {
     return(TextUtility.CutString(originalVal, startIndex, originalVal.Length));
 }
Beispiel #15
0
 /// <summary>
 /// 在数组索引中
 /// </summary>
 /// <param name="originalStr">原始字符串</param>
 /// <param name="strArray">字符串数组</param>
 /// <returns></returns>
 public static int InArrayIndexOf(string originalStr, string[] strArray)
 {
     return(TextUtility.InArrayIndexOf(originalStr, strArray, true));
 }
Beispiel #16
0
 /// <summary>
 /// 在数组中
 /// </summary>
 /// <param name="matchStr">匹配字符串</param>
 /// <param name="strArray">字符串数组</param>
 /// <param name="separator">分离器</param>
 /// <param name="ignoreCase">是否忽略大小写</param>
 /// <returns></returns>
 public static bool InArray(string matchStr, string strArray, string separator, bool ignoreCase)
 {
     return(TextUtility.InArray(matchStr, TextUtility.SplitStrArray(strArray, separator), ignoreCase));
 }
Beispiel #17
0
 /// <summary>
 /// 在数组中
 /// </summary>
 /// <param name="matchStr">匹配字符串</param>
 /// <param name="strArray">字符串数组</param>
 /// <param name="ignoreCase">是否忽略大小写</param>
 /// <returns></returns>
 public static bool InArray(string matchStr, string[] strArray, bool ignoreCase)
 {
     return(TextUtility.InArrayIndexOf(matchStr, strArray, ignoreCase) >= 0);
 }
Beispiel #18
0
 /// <summary>
 /// 格式日期时间
 /// </summary>
 /// <param name="oneDateVal">一个日期值</param>
 /// <param name="formatType">格式日期</param>
 /// <returns></returns>
 public static string FormatDateTime(string oneDateVal, int formatType)
 {
     return(TextUtility.FormatDateTime(DateTime.Parse(oneDateVal), formatType));
 }