当前位置: 技术问答>linux和unix
我想把新的字串替换掉一个文件当中某些指定字串内容该怎办呀???
来源: 互联网 发布时间:2016-06-25
本文导语: 我是在uinx环境下的。。。 这是一个order_name文件所写有的内容: BUSCODE01="10200001" SRC_DIRECTORY01="/settle1/idep/nec/out" ACC_DIRECTORY01="/settle1/idep/nec/ac" REFUSED_DIRECTORY01="/settle1/idep/nec/refused" LOG_DIRECTORY01="/spms/idep/InSquare/Log/ACFFrom1" COLLECT_SQUA...
我是在uinx环境下的。。。
这是一个order_name文件所写有的内容:
BUSCODE01="10200001"
SRC_DIRECTORY01="/settle1/idep/nec/out"
ACC_DIRECTORY01="/settle1/idep/nec/ac"
REFUSED_DIRECTORY01="/settle1/idep/nec/refused"
LOG_DIRECTORY01="/spms/idep/InSquare/Log/ACFFrom1"
COLLECT_SQUARE_SEAT01="/spms/idep/InSquare/0010/ACF/20090814_00021"
NAME_INCLUDE01="^NIC"
DOWNLOAD_BAK_FLAG01="YES"
...
现在就是我想在该order_name文件内容当中的SRC_DIRECTORY01字段所指的="/settle1/idep/nec/out"
这么一个路径改换成="/settle1/idep/nec/out1111111"这么另外的一个路径。
意思也就是说我想把字串char *newpath="/settle1/idep/nec/out1111111"写入到order_name文件当中替换掉之前SRC_DIRECTORY01这个字段所指的"/settle1/idep/nec/out"这路径。。我应该怎样来写程序操作呢??
SRC_DIRECTORY01、ACC_DIRECTORY01这些字段在文件当中都是唯一的。
|
其实这个也就是一个配置文件读写问题,网上找一下很多的,有现成的API,或者代码
|
不清楚。你直接改掉不就行了。你是想用什么办法改?
|
你这样太麻烦了替换的话,长度不一致容易覆盖到后面的字段,或者是有一段没替换掉
|
#include "StdAfx.h"
#include ".kxinifile.h"
这个是一个C++的。
class CKXIniFile : public CFile
{
public:
CKXIniFile(void);
CKXIniFile(CString strFileName);
virtual ~CKXIniFile(void);
public:
CString GetString(CString Section, CString Item, CString Value);
int GetInt(CString Section, CString Item, int Value);
void SetFileName(CString FileName);
void SetString(CString Section, CString Item, CString Value);
void SetInt(CString Section, CString Item, int Value);
BOOL WriteIniFile();
BOOL ReadIniFile();
int ReadLine(CString &strLine);
int WriteLine(CString strLine);
BOOL IsFileExist(){return m_bFileExist;}
protected:
void WriteFileString(CString Section, CString Item, CString Value);
CString GetFileString(CString Section, CString Item, CString Value);
private:
CString m_strFileName;//ini文件名
BOOL m_bFileExist;//文件是否存在
CStringArray m_FileContainer;//文件内容
};
CKXIniFile::CKXIniFile(void)
{
m_strFileName = "ini.ini";
m_bFileExist=FALSE;
}
CKXIniFile::CKXIniFile(CString strFileName)
{
m_strFileName = strFileName;
ReadIniFile();
}
CKXIniFile::~CKXIniFile(void)
{
//WriteIniFile();
if(m_FileContainer.GetSize() > 0)
{
m_FileContainer.RemoveAll();
}
}
int CKXIniFile::ReadLine(CString &strLine)
{
char ch;
strLine.Empty();
int nLen=0;
BOOL bLine = FALSE;
while ( bLine == FALSE )
{
int n = Read(&ch,1);
if(n
#include ".kxinifile.h"
这个是一个C++的。
class CKXIniFile : public CFile
{
public:
CKXIniFile(void);
CKXIniFile(CString strFileName);
virtual ~CKXIniFile(void);
public:
CString GetString(CString Section, CString Item, CString Value);
int GetInt(CString Section, CString Item, int Value);
void SetFileName(CString FileName);
void SetString(CString Section, CString Item, CString Value);
void SetInt(CString Section, CString Item, int Value);
BOOL WriteIniFile();
BOOL ReadIniFile();
int ReadLine(CString &strLine);
int WriteLine(CString strLine);
BOOL IsFileExist(){return m_bFileExist;}
protected:
void WriteFileString(CString Section, CString Item, CString Value);
CString GetFileString(CString Section, CString Item, CString Value);
private:
CString m_strFileName;//ini文件名
BOOL m_bFileExist;//文件是否存在
CStringArray m_FileContainer;//文件内容
};
CKXIniFile::CKXIniFile(void)
{
m_strFileName = "ini.ini";
m_bFileExist=FALSE;
}
CKXIniFile::CKXIniFile(CString strFileName)
{
m_strFileName = strFileName;
ReadIniFile();
}
CKXIniFile::~CKXIniFile(void)
{
//WriteIniFile();
if(m_FileContainer.GetSize() > 0)
{
m_FileContainer.RemoveAll();
}
}
int CKXIniFile::ReadLine(CString &strLine)
{
char ch;
strLine.Empty();
int nLen=0;
BOOL bLine = FALSE;
while ( bLine == FALSE )
{
int n = Read(&ch,1);
if(n