字符串切割:取出一个字符串中指定字符中间的字符串

字符串处理中经常会用到,贴在这里以备后续查阅。

使用: List<string> variables = SubStringByTwoChar("{""}","hfasfk{fdfd}yuyuy{888}ff{55}uuu{}dgdgd{89}"); 
 
public static List<string> SubStringByTwoChar(string tempStra, string tempStrb, string initStr)
       {
           List<string> SubStr = new List<string>();
         
           int i = 1;
           while (initStr.Contains(tempStra) && initStr.Contains(tempStrb))
           {
               int IndexofA = initStr.IndexOf(tempStra);
               int IndexofB = initStr.IndexOf(tempStrb);
               SubStr.Add(initStr.Substring(IndexofA + 1, IndexofB - IndexofA - 1));
               string af = initStr.Substring(IndexofB + 1);
               initStr = af;
               i++;
           }
           return SubStr;
       }

 

posted @ 2012-11-06 15:49  水月小妖  阅读(733)  评论(0编辑  收藏  举报