/// <summary> /// 将对象数组的每一项成员用左右字符串括起来 /// </summary> /// <param name="ss">目标对象数组</param> /// <param name="left">左边字符串</param> /// <param name="right">右边字符串</param> /// <returns>返回括起来后的字符串数组</returns> public static string[] Quote(this object[] ss, string left, string right) { string[] ar = new string[ss.Length]; for (int i = 0; i < ar.Length; i++) { ar[i] = Quote(TypeUtil.GetString(ss[i]), left, right); } return(ar); }
/// <summary> /// 将对象列表的每一项成员用左右字符串括起来 /// </summary> /// <param name="c">目标对象列表</param> /// <param name="left">左边字符串</param> /// <param name="right">右边字符串</param> /// <returns>返回括起来后的字符串列表</returns> public static IList Quote(this ICollection c, string left, string right) { ArrayList ls = new ArrayList(); foreach (object o in c) { ls.Add(Quote(TypeUtil.GetString(o), left, right)); } return(ls); }
/// <summary> /// 替换字符串 /// </summary> /// <param name="s">原字符串</param> /// <param name="replaceMap">替换Map</param> /// <param name="options">匹配规则,指定位可以包含:RegexOptions.Multiline, RegexOptions.IgnoreCase等</param> /// <returns>返回替换后的字符串</returns> public static string Replace(this string s, IDictionary replaceMap, RegexOptions options = RegexOptions.Multiline) { IList sl = new ArrayList(replaceMap.Keys); for (int i = 0; i < sl.Count; i++) { sl[i] = EscapeRegexSpecialChars(TypeUtil.GetString(sl[i])); } String ps = "|".Join(Quote(sl, "(", ")")); return(Regex.Replace(s, ps, new MapMatchEvaluator(replaceMap).OnEvaluator, options)); }
public static string OnTranslate(Match match) { string group = match.Value; return(TypeUtil.GetString(REGEX_CHARS_MAP[group], group)); }
public string OnEvaluator(Match match) { return(TypeUtil.GetString(this._map[match.Value])); }