string a="shhs;fsif;ewiewui;iweui;"
如何判断;号出现了多少次?不使用JS,要在后台的.cs文件中判断。求解

解决方案 »

  1.   

    split(";") 返回一个数组。  使用数组的属性length就OK/
      

  2.   

    string[] arr=a.Split(';');
    Regex.Matches("", ";").Count
    LINQ
      

  3.   

    string a="shhs;fsif;ewiewui;iweui;"
    return a.length-a.replace(";","").length
      

  4.   

    string[] arr=a.Split(';');
    int length=arr.length;//length还是Size()忘记了
      

  5.   

    string a=@"shhs;fsif;ewiewui;iweui;";
    int l = a.Split(';').Length-1;
      

  6.   


    楼上这个方法倒挺好
    在VB中这样才可以,C#中没有这个重载,得用Char
      

  7.   

    string a = "shhs;fsif;ewiewui;iweui;";
    char c = '?';
    //需要导入System.Text.RegularExpressions命名空间
    int count = Regex.Matches(a,Regex.Escape(new string(c,1))).Count;
      

  8.   

    遍历记数应该比以上方法效率都高,实现也简单string a = "shhs;fsif;ewiewui;iweui;";
    int count = 0;
    foreach (char c in a)
    {
        if (c == ';')
           count++;
    }
    richTextBox2.Text = count.ToString();对效率没要求那就无所谓了,否则Split和Replace效率都很低,是最不推荐的