string wxwStrLink = nu;???

解决方案 »

  1.   

    indexof返回的值,是这样的
    找到的话,当然好办
    没有找到的话就是-1
    你这里当然是一个死循环,找不到就是-1,++操作后也不过是个0,而end是一个大于0 的数字,这不是死循环是什么?
    还有,indexof都是返回第一个匹配项的index值,你所要找的并不是你的程序找到的,它只能找到第一个“>”,那么它的index在你的程序里面应该是4,并不是末尾,当找了第一次之后,在循环进入第二此的时候就start就变成-1了给你一个修改意见:
    在你的wxwContent与wxwDate后面加上“$”或是别的什么不会使用在你的字符串里的符号做结尾符,在计算end的时候就indexof("$")或是indexof('$')
    然后你的程序的其他地方就不需要更改了
      

  2.   

    呵呵,来晚了点,国庆Happy去了这个可以用ArrayList来做,也可以用HashTable,这里贴出ArrayList的办法,你的想法也可以,不过增加了复杂度,感觉还是用ArrayList最方便:ArrayList contentList = new ArrayList();
    ArrayList dateList = new ArrayList();contentList.Add("900");//contentList[0]
    contentList.Add("68");//contentList[1]
    contentList.Add("1");//contentList[2]dateList.Add("2004-10-1");//dateList[0]
    dateList.Add("2004-10-2");//dateList[1]
    dateList.Add("2004-10-4");//dateList[2]//序号一一对应。并且contentList中的内容最好唯一,否则IndexOf会定位不准确//wxwStrLink是id号,比如说是1,68,这是用户选择的
    string wxwStrLink = numUserInput;//假如用户选择的是68
    // contentList.IndexOf("68") = 1;dateList.RemoveAt(1), 即移除dateList[1]
    dateList.RemoveAt( contentList.IndexOf(wxwStrLink));
    contentList.Remove( wxwStrLink );//删除"68"
      

  3.   

    能不能换种方法?如把两个字符串变成数组,当第一个数组的某个元素被删除时,只要得到了它的下标,便能将第二个数组的对应元素删除。。
    可以用string.Split()方法来将字符串进行分组。试一下//----------分割字符串-------------------------------------string  wxwContent ="<900><68><1>";
    string wxwDate ="<2004-10-1 ><2004-10-2 ><2004-10-4 >";
    string [] array1=wxwContent.Split(new Char[]{'<','>'});
    string [] array2=wxwDate.Split(new Char[]{'<','>'});/*  如果没有错的话,数组内容应该变成
        如array1的内容为{<,900,><,68,><,1,>}  
        数组长度为7
    */
    //---------下面的是删除------------------------------------
    int a=0;
    foreach(string str in array1)
    {
        if(str=="68")
        {
             这里写删除array2[a]元素
        }
        a++;
    }代码随手写的,未经测试,在此只提供一个思路,请高手指正!!
      

  4.   

    楼主的方法就不错,现有情况来看!你的代码有点问题|
      while(start<=end)
      {

      start = wxwContent.IndexOf("<",start,end-start);
      start++;
      count++;
      }
      改成
      while(start<=end)
      { string a=wxwCountent.Substring(start,1);
        if(a.Equals("<"))
        {
          count++;
         }
        start++;
      }
      

  5.   

    用数组、arraylist或者hashtable都可以实现,而且实现起来比较简单。
      

  6.   

    大哥们:
    用数组(arraylist,hashtable)就不用在这上面发帖了,没办法!
      

  7.   

    indexof返回的值,是这样的
    找到的话,当然好办
    没有找到的话就是-1
    可以这样
      while(start<=end&&start!=-1)
         {

         start = wxwContent.IndexOf('<',start,end-start);

                                   
        if(start!=-1)
            {
    startValue=start;
    }
          if(start==-1)
    break;
         start++;
         count++;
          }
      

  8.   

    楼主可以建立一个对应关系,string的几个对应于下面的string的几个就可以.
    其实还是用数组比较好一点.
      

  9.   

    --------------
    int a =0
    while(dateCount!=count&&start<=end&&start!=-1)
     {

       start = wxwDate.IndexOf('<',start,end-start);
       if(start==-1)
        {
    break;
         }
       else
        {
         a=start;
        }
        start++;
       dateCount++;
    }
      

  10.   

    楼主写的不错啊。稍改就可以了。
    如:string wxwStrLink = “68”;
    1。while(start<=end)======>>>>>>>>>while(start<end)
    2。wxwDate.Remove(start-1,12);=====>>>>wxwDate = wxwDate.Remove(start-1,12);
    wxwContent=wxwContent.Remove(wxwIndex-1,wxwStrLink.Length+2);