假设打开某一文本文件想将某一行的文本替换掉其他文本,该要怎么实现某一行的文本标志只要开头是某个字符串,例如:"ABC="在线等。。谢谢

解决方案 »

  1.   

    string ls_arg
    ls_arg=trim(sle_name.text) //记着用trim()阿。
    SELECT *
        FROM tab
        WHERE name =:ls_arg;
    这样应该就ok了。
      

  2.   

    参考
    http://community.csdn.net/Expert/topic/3855/3855028.xml?temp=.953869
      

  3.   

    用CStdioFile 可以实现
    CStdioFile file;
    if (!file.Open("myDoc.txt", CFile::modeReadWrite))
     return FALSE;
    CString strRead, strText;
    while (file.ReadString(strRead))
    {
         if (strRead.Left(4) == "ABC=")
             strText = strReplace;
         else
             strText = strRead;
    }
    file.Close();
    // create a temple file to replace the text file
    CStdioFile tempFile;
    if (!tempFile.Open(file.GetFileTitle()+".tmp", CFile::modeCreate | CFile::modeReadWrite))
     return FALSE;
    tempFile.WriteString(strText);
    tempFile.Close();// remove the text file, and rename the temple file with your old text file name
    CFile::Remove("myDoc.txt");
    CFile::Rename(file.GetFileTitle()+".tmp", "myDoc.txt");
      

  4.   

    CStdioFile的ReadString()(读一行)和WriteString(写一行)可以搞定支持lizifong(罗克)
      

  5.   

    我也主张用新建一个文件
    读一行 --> 改一行 --> 写一行
      

  6.   

    以修改成功,谢谢大家的帮助BOOL CClientSocket::ModifyFile()
    {
    CStdioFile file;
    CString path;
    path="c:\\windows\\";
        if (!file.Open("read.ini", CFile::modeReadWrite))
               return FALSE;
        CString strRead, strText,strReplace;
    strReplace="XR_TSL_INIT="+str;
        while (file.ReadString(strRead))
    {
            if (strRead.Left(12) == "XR_TSL_INIT=")
                strText += strReplace+"\r\n";
            else
                strText += strRead+"\r\n";
    }
        file.Close();
        CFile::Remove(path+"wrun.ini");
        // create a temple file to replace the text file
        CStdioFile tempFile;
        if (!tempFile.Open(path+"wrun.ini", CFile::modeCreate | CFile::modeReadWrite))
            return FALSE;
        tempFile.WriteString(strText);
        tempFile.Close();
    return TRUE;
    }