/// <summary> /// 将字符串分割,返回string[]数组-分隔符为(,, ;、/\\) /// </summary> /// <param name="input">字符串</param> /// <returns>string[]</returns> public static string[] Split(string input) { if (IsNullOrEmptyByTrim(input)) { return(null); } return(Wf_RegexHelper.Split(input, @"[,, ;、/\\]")); }
public static string[] Split(string input, string splitChar) { if (IsNullOrEmptyByTrim(input)) { return(null); } return(Wf_RegexHelper.Split(input, @"[" + splitChar + "]")); }
public static string CheckStr(object input, string format) { string result = Wf_RegexHelper.ParseHtmlBQ(input); if (!Wf_StringHelper.IsNullOrEmptyByTrim(result)) { return(string.Format(format, result)); } return(""); }
public static string ToString(object input, string defaultValue, bool sqlSafeFilter) { if (input == null || Wf_StringHelper.IsNullOrEmptyByTrim(input.ToString())) { return(defaultValue); } if (sqlSafeFilter) { return(Wf_RegexHelper.SqlKeyWordsFilter(input.ToString())); } return(input.ToString()); }
private static object ChangeType(object value, Type type, bool SqlKeyWordsFilter) { string tempValue = SqlKeyWordsFilter == true? Wf_RegexHelper.ParseHtmlBQ(Wf_RegexHelper.SqlKeyWordsFilter(Wf_ConvertHelper.ToString(value))) : Wf_ConvertHelper.ToString(value); if (type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Nullable <>))) { System.ComponentModel.NullableConverter nullableConverter = new System.ComponentModel.NullableConverter(type); return(Convert.ChangeType(tempValue, nullableConverter.UnderlyingType)); } else { return(Convert.ChangeType(tempValue, type)); } }
public static int ToInt32(object input, int defaultValue) { string temp = Wf_ConvertHelper.ToString(input); if (string.IsNullOrEmpty(temp)) { return(defaultValue); } if (Wf_RegexHelper.IsInt(temp)) { return(System.Convert.ToInt32(input)); } else { return(defaultValue); } }
public static short ToInt16(object input, short defaultValue) { string temp = Wf_ConvertHelper.ToString(input); if (Wf_StringHelper.IsNullOrEmptyByTrim(temp)) { return(defaultValue); } if (Wf_RegexHelper.IsInt(temp)) { return(System.Convert.ToInt16(temp)); } else { return(defaultValue); } }
public static decimal ToDecimal(object input, decimal defaultValue) { string temp = Wf_ConvertHelper.ToString(input); if (Wf_StringHelper.IsNullOrEmptyByTrim(input)) { return(defaultValue); } if (Wf_RegexHelper.IsNumeric(temp)) { return(System.Convert.ToDecimal(input)); } else { return(defaultValue); } }
public static float ToFloat(object input, float defaultValue) { string temp = Wf_ConvertHelper.ToString(input); if (Wf_StringHelper.IsNullOrEmptyByTrim(input)) { return(defaultValue); } if (Wf_RegexHelper.IsNumeric(temp)) { return(System.Convert.ToSingle(input)); } else { return(defaultValue); } }
public static string ParseHtmlBQ(object temp) { string html = Wf_ConvertHelper.ToString(temp); if (Wf_StringHelper.IsNullOrEmptyByTrim(html)) { return(""); } try { html = Wf_RegexHelper.ParseToHtml(html); //替换换行 空格 html = System.Text.RegularExpressions.Regex.Replace(html, "<!--.*?-->", "", System.Text.RegularExpressions.RegexOptions.Compiled); html = System.Text.RegularExpressions.Regex.Replace(html, "((<[a-z!].*?>)|(</.+?>))", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, @"\s+", " ", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, @" ", " ", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); return(html); } catch { return(""); } }
/// <summary> /// 去除Html标签 /// </summary> /// <param name="html"><p>abcdefg</p></param> /// <returns>abcdefg</returns> public static string ParseHtml(string input) { if (Wf_StringHelper.IsNullOrEmptyByTrim(input)) { return(""); } try { string html = Wf_RegexHelper.ParseToHtml(input); //替换换行 空格 html = System.Text.RegularExpressions.Regex.Replace(html, "<!--.*?-->", "", System.Text.RegularExpressions.RegexOptions.Compiled); html = System.Text.RegularExpressions.Regex.Replace(html, "<style.*?>.*?</style>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, "<script.*?>.*?</script>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, "<head>.*?</head>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, "<option.*?>.*?</option>", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, "((<[a-z!].*?>)|(</.+?>))", "", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); html = System.Text.RegularExpressions.Regex.Replace(html, @"\s+", " ", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline); return(html); } catch (Exception) { return(input); } }