//获取某一列值
string orderids = (from d in dt.AsEnumerable() select d.Field("OrderID")).ToList().ListToString();
///
/// 判断字符串是否在某字符串数组当中
///
///
///
///
public static bool In(this string value, params string[] items)
{
return items.Any(item => value == item);
}
///
/// 判断字符串是否在某字符串数组当中
///
///
///
///
public static bool In(this Enum value, params Enum[] items)
{
return items.Any(item => value.Equals(item));
}
///
/// 判断字符串是否在另一字符当中出现
///
///
///
///
public static bool Like(this string value, string param)
{
return value.Contains(param);
}
///
/// 将List数组转化成分隔的字符串
///
///
///
public static string ListToString(this IList values, char split = ',')
{
var result = string.Empty;
foreach (var item in values)
{
result += item.ToString() + split;
}
result = result.TrimEnd(split);
return result;
}
///
/// 判断字符串是null或者string.Empty
///
///
///
public static bool IsNullOrEmpty(this string value)
{
return string.IsNullOrEmpty(value);
}
///
/// 对象转字符串,null返回空字符串
///
///
///
public static string ObjectToString(this object obj)
{
if (obj == null)
{
return string.Empty;
}
return obj.ToString().Trim();
}
///
/// 过滤Xml特殊字符
///
///
///
public static string FilterSpecailCharOfXml(this string str)
{
var value = str.ObjectToString();
value = value.Replace("'", " ");
value = value.Replace("\"", " ");
value = value.Replace("
value = value.Replace(">", " ");
//value = value.Replace("&", " ");
return value;
}
///
/// 过滤空白字符
///
///
///
public static string FilterWhiteSpace(this string str)
{
Regex whitespace = new Regex(@"\s+", RegexOptions.Compiled);
return whitespace.Replace(str, "");
}
///
/// 首拼查询
///
///
///
///
public static bool FirstLike(this string strText, string firstChar)
{
int len = strText.Length;
string myStr = "";
for (int i = 0; i < len; i++)
{
myStr += getSpell(strText.Substring(i, 1));
}
return myStr.Contains(firstChar.ToUpper());
}