using System; using System.Collections.Generic; using System.Linq; namespace HT.Cloud.Code { public class TextHelper { /// /// 获取默认值 /// /// /// /// public static string GetCustomValue(string value, string defaultValue) { if (string.IsNullOrEmpty(value)) { return defaultValue; } else { return value; } } /// /// 截取指定长度的字符串 /// /// /// /// public static string GetSubString(string value, int length, bool ellipsis = false) { if (string.IsNullOrEmpty(value)) { return value; } if (value.Length > length) { value = value.Substring(0, length); if (ellipsis) { value += "..."; } } return value; } /// /// 字符串转指定类型数组 /// /// /// /// public static T[] SplitToArray(string value, char split) { T[] arr = value.Split(new string[] { split.ToString() }, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToArray(); return arr; } /// /// 判断是否有交集 /// /// /// /// /// public static bool IsArrayIntersection(List list1, List list2) { List t = list1.Distinct().ToList(); var exceptArr = t.Except(list2).ToList(); if (exceptArr.Count < t.Count) { return true; } else { return false; } } } }