All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL,Server,2005数据库开发概述(1)_[SQL,Server教程]
Windows,Vista下安装SQL,Server,2005_mssql学习_编程技术
c#中连接SqL2005数据库错误解决及转义字符_.net资料_编程技术
asp.net2.0服务器控件之FileUpload控件
C#程序设计入门经典之C#的基本语法_[Asp.Net教程]
浅谈PHP开发中MySQL数据库索引的经验_php资料_编程技术
PHP实例:PHP制作的网站意见在线反馈表_[PHP教程]
C#应用:读取指定盘符的硬盘序列号_[Asp.Net教程]
.Net业务平台的数值精度陷阱与解决方法_.net资料_编程技术
小例子:ASP.NET定制简单的错误处理页面_.net资料_编程技术
Reading number is top 10 pictures
有种屌丝级别的好妹子
China's first snake village2
福利福利。。。。。。
Discharge accidentally Actresses by the breast3
NeedWallpaper2
LiXiang early youth photo
Summer is most suitable for young people to travel in China2
The money of more than 100 countries and regions15
Startling Russian girl blind date scene1
青春清纯美女大集合1
Download software ranking
金山office2007
Adobe Flash Player(IE) 10.0.32.18 浏览器专用的FLASH插件
尖东毒玫瑰B
Be there or be square
豪门浪荡史
Professional killers2 for Android
圣殿祭司的ASP.NET.2.0.开发详解-使用C#
Unix video tutorial20
I'm come from Beijing2
Sora aoi's film--cangkong_Blue.Sky
aaa published in(发表于) 2013/12/18 8:06:30 Edit(编辑)
一个使用C#自写的SPLIT函数的代码_.net资料_编程技术

一个使用C#自写的SPLIT函数的代码_.net资料_编程技术

一个使用C#自写的SPLIT函数的代码_.net资料_编程技术-你的首页-uuhomepage.com

  因为C#的SPLIT局限性比较大,只能用字符或字符数组来做分隔符。没有提供像VB一样的可以用字符串做分割符的SPLIT函数,这样在写程序过程中,少了很多便利。  于是,就写了如下一个函数来方便自己编程。


  程序如下:



  =====================================================
  using System;
  using System.Collections;
  namespace split
  ...{
  class mySplit
  ...{
  [STAThread]
  static void Main(string[] args)
  ...{
  string str1="",str2="";
  if(args.Length != 2)
  ...{
  Console.WriteLine("请输入要分割的字符串:");
  str1 = Console.ReadLine();
  Console.WriteLine("请输入分割符:");
  str2 = Console.ReadLine();
  Console.WriteLine(" 分割出的数据如下: ");
  }
  else
  ...{
  str1 = args[0];
  str2 = args[1];
  }
  string[] output = null;
  output = split(str1,str2);
  for (int i=0; i < output.Length; i++)
  ...{
  Console.WriteLine("{0}", output[i]);
  }
  Console.WriteLine(" 被分割成{0}份字符串!", output.Length);
  TimeSpan sp1,sp2,sp3;
  DateTime dt = DateTime.Now;
  for(int i=0; i<1000; i++)
  ...{
  output=split(str1,str2);
  output=null;
  }
  sp1=DateTime.Now - dt;
  //用&&符分割!
  System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex("&{2}");
  dt = DateTime.Now;
  for(int j=0; j<1000; j++)
  ...{
  output=rg.Split(str1);
  output=null;
  }
  sp2=DateTime.Now - dt;
  Console.WriteLine(" 正则式类执行时间:{0}", sp2.ToString());
  Console.WriteLine("自制函数执行时间:{0}", sp1.ToString());
  Console.WriteLine(" 输入回车退出程序!");
  Console.Read();
  }
  //分割函数开始
  public static string[] split(string strinput, string sp)
  ...{
  string tmp="";
  int strlen=0, splen=0;
  int found=0;
  string[] rt = null;
  try
  ...{
  if(strinput==null || sp==null || strinput.Length==0 || sp.Length==0) return null;
  //初始化一个数组列表(当做动态数组)
  ArrayList tmp3 = new ArrayList();
  strlen = strinput.Length;
  splen = sp.Length;
  for(int i=0; i
  ...{
  //查找分隔符
  found = strinput.IndexOf(sp, i);
  if(found>=0)
  ...{
  tmp = "";
  //取分隔符前的字符串
  tmp = strinput.Substring(i, found-i);
  //添加到数组列表
  tmp3.Add(tmp);
  i = found+splen-1;
  }
  else
  ...{
  string tmp2="";
  //取最后的字符串
  tmp2 = strinput.Substring(i);
  if(tmp2 != "")
  tmp3.Add(tmp2);
  break;
  }
  }
  //将动态数组的维数设置成实际存在的元素个数,因为数组列表是以16的倍数递增维数的
  tmp3.TrimToSize();
  //转换数组列表为字符串数组,并返回。
  rt = (string[])tmp3.ToArray(typeof(String));
  tmp3.Clear();
  }
  catch (Exception e)
  ...{
  //Console.WriteLine("{0}", e.Message);
  throw e;
  }
  return rt;
  }
  }
  }



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.