标签替换(委托)

 

//[email protected] class CTagReplace { /// <summary> /// 申明单个匹配的标签处理函数 /// </summary> /// <param name="input"></param> /// <returns></returns> protected delegate string ReCallBack(string input); /// <summary> /// 单个匹配的标签处理逻辑 /// </summary> /// <param name="input">单个便签值</param> /// <returns>处理结果</returns> protected string ReSingleHandle(string input) { return input + "11111"; } /// <summary> /// 整个字符串处理函数 /// </summary> /// <param name="t">原始字串</param> /// <param name="split1">标签前缀</param> /// <param name="split2">标签后缀</param> /// <param name="resiglehandle">单个标签处理函数</param> /// <returns>处理后的结果</returns> protected string ReplaceTag(string t, string split1, string split2, ReCallBack resiglehandle) { int i = 1; while (i < 100000) { int p1 = t.IndexOf(split1); if (p1 == -1) break; int p2 = t.IndexOf(split2); string f = t.Substring(p1 + split1.Length, p2 - split2.Length - p1); f = resiglehandle(f); t = t.Substring(0, p1) + f + t.Substring(p2 + split2.Length); i++; } return t; } } 

你可能感兴趣的:(String,input)