using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Wood.Util { 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; } } }