当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: 谢谢。 ......
    摘要: 请问:怎样得到tstrings或tstringlist的一个实例的字符串数组的长度? ......


C#中字符串分解的问题

"2003-3"分解成"2003"和"3"写成如下形式出错!  
   
  s_time.Substring(0,s_time.IndexOf("-",0,s_time.Length));    
  s_time.Substring(s_time.IndexOf("-",0,s_time.Length)   +   1,s_time.Length   -   s_time.IndexOf("-",0,s_time.Length));  
   
  各位指点一下!!!  
   
   
  谢谢!!!

NO.1   作者: zlcoolzl

你可以这样写,也可以分割:  
  string   s_time   =   "2003-3";  
  string[]   StrTemp   =   s_time.Split(-);  
 

NO.2   作者: cmsoft

string   str="2003-3";  
  char[]   Sp   =   new   char[1];  
  Sp[0]=-;  
  string[]   arry=str.Split(Sp);  
  Response.Write(arry[0].ToString());     //"2003"  
  Response.Write(arry[1].ToString());     //"3"

NO.3   作者: 117hn

哦,写错了  
  s_time.Remove(0,s_time.LastIndexOf("-")+1);取之后  
          s_time.Substring(0,s_time.IndexOf("-"));取之前  
 

NO.4   作者: mh51

正确代码如下:  
  string   s_time="2003-5";  
   
  //串的序是从0~Length-1,当序到了Length时已越界!  
   
  //得到“2003”  
  Label1.Text=s_time.Substring(0,s_time.IndexOf("-",0,s_time.Length-1));    
                                                                     
  //得到“5”  
  Label2.Text=s_time.Substring(s_time.IndexOf("-",0,s_time.Length-1)   +   1,s_time.Length-1   -   s_time.IndexOf("-",0,s_time.Length-1));  
   
  仔细阅读一下系统的错误提示,会对你分析调试程序有帮助的!  
   
  另外,用Substring()确实较繁,建议用Split()简洁明了得多。     ^-^


 ·有关activex控件开发的问题    »显示摘要«
    摘要: 问一个比较简单的问题,在开发ocx控件的时候,一般添加属性时,如果一个属性值有两种不同的选项,可以将类型设置为布尔型,但是如果超过两个,有三个或更多的时候,类型设置应该是什么呢,也或者有两个选项,但我不希望用true和false来表示,就比如label控件的alignment属性,它有靠左(0),靠右(1)和居中(2)三个选项,这个怎么实现呢? ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE