水晶报表自定义函数(替换并截取特殊字符后内容)

's待处理的参数
Function cheakdepart ( s as string)
'先进行判断
      '声明已知字符串的字节数、">"所在位置的变量
    Dim n As Number  , m As Number
    '声明字符串变量

    Dim s0 as string  

‘如果包含">"符号截取其后文本       

        if (">" in s) then    
        For n = 1 To Len(s) '这里用了Len函数来计算已知字符串的字节数
        m = InStr(s, ">", -1) '">"所在的位置(其中的-1是默认的)
        '显示第一个">"后面的字符串
        s0 = Right(s, Len(s) - m)
        next n

        s0=Replace (s0, ">"," " )

’否则直接输出

        else
        s0=s
        end if
    cheakdepart =s0

End Function

 

 

 

 

 

 

string str="8,9,10,11,12,13";
string[] count=str.split(',')

返回的count.length就是6!

 

 INSTR()函数,有返回值就说名存在

 

报告指定的   String   在此实例中的第一个匹配项的索引。  
   
  [Visual   Basic]  
  Overloads   Public   Function   IndexOf(   _  
        ByVal   value   As   String   _  
  )   As   Integer  
   
  [C#]  
  public   int   IndexOf(  
        string   value  
  );  
   
  [C++]  
  public:   int   IndexOf(  
        String*   value  
  );  
   
  [JScript]  
  public   function   IndexOf(  
        value   :   String  
  )   :   int;  
   
  参数  
  value    
  要查找的   String。    
  返回值  

  如果找到该字符,则为   value   的索引位置;如果未找到该字符,则为   -1。如果   value   为   Empty,则返回值为   0。   

 

 

 

int idx=str.IndexOf(",",0,n);
string newstr=str.SubString(0,idx);

newstr就是你想要的.

------------------

那这样儿:

string[] s=str.Split(',');
string newstr="";
for(int iii=0;iii<n;iii++){
newstr=newstr+s[iii]+",";
}
newstr=newstr.Substring(0,newstr.Length-1);


posted @ 2009-02-18 16:25  云海之上  阅读(1973)  评论(1编辑  收藏  举报