我想把文本文件中的一段字符串替换掉,但是我不知道这段字符串是什么,我只知道这段字符串两头的文字,请大家给个程序段,我参考一下
谢谢了

解决方案 »

  1.   

    CString str = text; int l1 = str.Find("");     //找到要替换内容的起始位置
    int l2 = str.Find("",l1);  //找到要替换内容的终止位置str.Delete(str,l2-l1);         //先将要替换的内容删除
    str.Insert(l1,"new string");   //然后向该位置插入字符串//CString本来带有一个Replace函数,但是这个函数只接受2个参数,旧字符串和新字符串,不太灵活
      

  2.   

    char buf[64002];
    memset(buf,0,64002);
    CFile f;
    f.Open("1.txt",CFile::modeRead);
    f.Read(buf,64000);
    f.Close();
    char *b,*p;
    b=strstr(buf,"头");
    p=strstr(buf,"尾");
    p+=2;//尾的长度
    strcpy(b,p);f.Open("1.txt",CFile::modeCreate|CFile::modeWrite);
    f.Write(buf,strlen(buf));
    f.Close();