string hits=@"1,58; 1,167; 1,11; 2,154; 3,15; 4,11; 4,16; 14;13 ";请问如何把hits如 1,58 1,167 的头个数字取出来,得到一个数组里面是 1 2 3 4 14

解决方案 »

  1.   

    hits也可以不用string 类型.数组可以是任意数组.
      

  2.   

    string[] hitArray = hits.Split('');
    for (int i=0;i<hitArray.Length;i++)
    {
       Console.Write(hitArray[i].Splite(',')[0]);
    }
      

  3.   

    string[] hitArray = hits.Split(';');
    for (int i=0;i<hitArray.Length;i++)
    {
       Console.Write(hitArray[i].Splite(',')[0]);
    }
      
     
    Top  
      

  4.   

    string hits=@"1,58; 1,167; 1,11; 2,154; 3,15; 4,11; 4,16; 14,13 ";

    string [] temp = hits.Split(';');
    int [] result = new int[temp.Length];
    int count = 1;

    result[0] = Convert.ToInt32 ( temp[0].Split(',')[0] );

    for ( int i = 1; i < temp.Length; i++ )
    {
    int num = Convert.ToInt32 ( temp[i].Split(',')[0] );
    if ( result[count - 1] != num )
    {
    result[count] = num;
    count++;
    }
    }
      

  5.   

    太谢谢各位了.NuclearG的很不错.但是有个问题
    int [] result = new int[temp.Length];取出来 result数组的长度是8,到那时取出来的时候应该只有5个