最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

在asp.NET中字符串替換的五種方法

 更新時(shí)間:2008年11月20日 14:22:14   作者:  
asp.NET中字符串替換方法小結(jié)

測(cè)試
以下為引用的內(nèi)容: 
復(fù)制代碼 代碼如下:

staticvoidMain(string[]args)
{
  stringsegment="AaBbCc";
  stringsource;
  stringpattern="AbC";
  stringdestination="Some";
  stringresult="";
  
  constlongcount=1000;
  StringBuilderpressure=newStringBuilder();
  HiPerfTimertime;
  for(inti=0;i<count;i++)
  {
    pressure.Append(segment);
  }
  source=pressure.ToString();
  GC.Collect();
  //regexp
  time=newHiPerfTimer();
  time.Start();
  for(inti=0;i<count;i++)
  {
    result=Regex.Replace(source,pattern,
         destination,RegexOptions.IgnoreCase);
  }
  time.Stop();
  Console.WriteLine("regexp  ="+time.Duration+"s");
  GC.Collect();
  //vb
  time=newHiPerfTimer();
  time.Start();
  for(inti=0;i<count;i++)
  {
    result=Strings.Replace(source,pattern,
         destination,1,-1,CompareMethod.Text);
  }
  time.Stop();
  Console.WriteLine("vb    ="+time.Duration+"s");
  GC.Collect();
  //vbReplace
  time=newHiPerfTimer();
  time.Start();
  for(inti=0;i<count;i++)
  {
    result=VBString.Replace(source,pattern,
         destination,1,-1,StringCompareMethod.Text);
  }
  time.Stop();
  Console.WriteLine("vbReplace="+time.Duration+"s");//+result);
  GC.Collect();
  //ReplaceEx
  time=newHiPerfTimer();
  time.Start();
  for(inti=0;i<count;i++)
  {
    result=Test.ReplaceEx(source,pattern,destination);
  }
  time.Stop();
  Console.WriteLine("ReplaceEx="+time.Duration+"s");
  GC.Collect();
  //Replace
  time=newHiPerfTimer();
  time.Start();
  for(inti=0;i<count;i++)
  {
    result=source.Replace(pattern.ToLower(),destination);
  }
  time.Stop();
  Console.WriteLine("Replace ="+time.Duration+"s");
  GC.Collect();
  //sorry,twoslow:(
  /*//substring
  time=newHiPerfTimer();
  time.Start();
  for(inti=0;i<count;i++)
  {
    result=StringHelper.ReplaceText(source,pattern,
         destination,StringHelper.CompareMethods.Text);
  }
  time.Stop();
  Console.WriteLine("substring="+time.Duration+":");
  GC.Collect();
  //substringwithstringbuilder
  time=newHiPerfTimer();
  time.Start();
  for(inti=0;i<count;i++)
  {
    result=StringHelper.ReplaceTextB(source,pattern,
          destination,StringHelper.CompareMethods.Text);
  }
  time.Stop();
  Console.WriteLine("substringB="+time.Duration+":");
  GC.Collect();
  */
  Console.ReadLine();
}
1?¢stringsegment="abcaBc";
regexp=3.75481827997692s
vb=1.52745502570857s
vbReplace=1.46234256029747s
ReplaceEx=0.797071415501132s!!!<FONTcolor=gray>Replace=0.178327413120941s</FONT>
//ReplaceEx>vbReplace>vb>regexp
2?¢stringsegment="abcaBcabC";
regexp=5.30117431126023s
vb=2.46258449048692s
vbReplace=2.5018721653171s
ReplaceEx=1.00662179131705s!!!
<FONTcolor=gray>Replace=0.233760994763301s</FONT>
//ReplaceEx>vb>vbReplace>regexp
3?¢stringsegment="abcaBcabCAbc";
regexp=7.00987862982586s
vb=3.61050301085753s
vbReplace=3.42324876485699s
ReplaceEx=1.14969947297771s!!!
<FONTcolor=gray>Replace=0.277254511397398s</FONT>
//ReplaceEx>vbReplace>vb>regexp
4?¢stringsegment="ABCabcAbCaBcAbcabCABCAbcaBC";
regexp=13.5940090151123s
vb=11.6806222578568s
vbReplace=11.1757614445411s
ReplaceEx=1.70264153684337s!!!(mygod!)
<FONTcolor=gray>Replace=0.42236820601501s</FONT>
//ReplaceEx>vbReplace>vb>regexp

查看程序的Block在:
以下為引用的內(nèi)容:
復(fù)制代碼 代碼如下:

stringupperString=original.ToUpper();
stringupperPattern=pattern.ToUpper();

如果需要敏感,就免了這2行。
解釋:先建一個(gè)char[]類型的變量采訪替換后的字符,其大小就是最大可能被替換的字符,例如ABABAB,替換AB成C,其獲取過(guò)程就是ABABAB最大可能包括的AB的數(shù)目乘以AB多于C的數(shù)目,
以下為引用的內(nèi)容:
  char[]chars=newchar[original.Length+Math.Max(0,inc)];
  ,inc不一定大于零。

然后循環(huán),用IndexOf索引。賦值。。。判斷,返回。

相關(guān)文章

最新評(píng)論

清水河县| 荆门市| 儋州市| 迁西县| 东阳市| 工布江达县| 孟津县| 周宁县| 邹城市| 青龙| 五常市| 衡阳县| 宜良县| 古丈县| 永福县| 秦皇岛市| 方城县| 长葛市| 正阳县| 体育| 玉树县| 金坛市| 九江县| 枣强县| 仙桃市| 噶尔县| 西峡县| 松潘县| 邵武市| 安化县| 黔西| 明水县| 乌兰浩特市| 麻江县| 安义县| 上犹县| 麻栗坡县| 桦川县| 太和县| 阳朔县| 青河县|