现在我通过前面的处理 得到了一个字符串数组 string[] s ,元素个数未知,元素内容仅为空字符串或者是英文单词,现在我想得到非空字符串的元素个数,也即英文单词的个数,但是我不想用for或者foreach循环去遍历这个数组,可不可以调用类库提供的某些方法直接得到呢???请高手不惜赐教!!

解决方案 »

  1.   

    你可以如下进行处理:
    string strValue = string.Join( " ", s );
    Regex regWord = new Regex( "[a-zA-Z]+" );//Match word
    foreach( Match m in regWord.Matches( strValue )
    {
          Debug.WriteLine( m.Value );
    }
      

  2.   

    string[] sourceArray = .....
    string strInput =.....
    int res = Array.BinarySearch( sourceArray , strInput );
    if( res > 0 )
       找到
    else
       没找到
      

  3.   

    不用循环估计没有其它的方法。关注ing。
      

  4.   

    “我不想用for或者foreach循环去遍历这个数组”
    lz: 
      用for或者foreach循环去遍历,本来是很简单,又实用的办法,为什么非要找其他途径,基于什么考虑呢????
      

  5.   

    弄弄。呵呵。
    比如有空格,分隔符为,的话
    str=str.Replace(" ","");
    arr=str.Split(',');
    arr.Lenght即是英文数量
      

  6.   

    对不起,少了一句。补上。
    比如有空格,分隔符为,的话
    str=str.Replace(" ","");
    str=str.Replace(",,",",");
    arr=str.Split(',');
    arr.Lenght即是英文数量