예제 #1
0
        /// <summary>
        /// 格式化字符串
        /// </summary>
        /// <returns></returns>
        private static string FormatDateTime(string dateTime, string format)
        {
            StringBuilder ret = new StringBuilder();


            List <string> lstPart = MyReplacer.SplitItems(format, _lstItems);

            for (int i = 0; i < lstPart.Count; i++)
            {
                string part      = lstPart[i];
                string newString = null;
                if (_dicDateTimeItem.TryGetValue(part, out newString))
                {
                    ret.Append(newString.Replace("{dt}", dateTime));
                }
                else
                {
                    ret.Append("'");
                    ret.Append(part);
                    ret.Append("'");
                }

                if (i < lstPart.Count - 1)
                {
                    ret.Append("+");
                }
            }


            return(ret.ToString());
        }
    void replacingMethod() {
       Regex r = new Regex("<.*>");
		
       MyReplacer r = new MyReplacer();
       // Assign the replace method to the MatchEvaluator delegate.
       MatchEvaluator myEvaluator = new MatchEvaluator(r.Replace);
       // Replace matched characters using the delegate method.
       sInput = r.Replace(sInput, myEvaluator);
    }
예제 #3
0
 /// <summary>
 /// 按照条件替换字符串
 /// </summary>
 /// <param name="source">源字符串</param>
 /// <param name="conditions">替换条件集合</param>
 /// <returns></returns>
 public static string ReplaceString(string source, IEnumerable <ReplaceItem> conditions)
 {
     return(MyReplacer.Replace(source, conditions));
 }