我一直有一点麻烦与我的查找和替换功能,我可以让它取代所有字符,但我只希望它改变匹配被禁止的字的字符。发现字符串向量中的特定字符时发现C++
这里是我到目前为止的代码
class getTextData
{
private:
string currentWord;
vector<string> bannedWords;
vector<string> textWords;
int bannedWordCount;
int numWords;
char ch;
int index[3];
ifstream inFile();
public:
void GetBannedList(string fileName);
void GetWordAmount(string fileName);
void GetDocumentWords(string fileName);
void FindBannedWords();
void ReplaceWords(string fileOutput);
};
for(int i = 0; i <= numWords; i++)
{
for(int j = 0; j < bannedWordCount; j++)
{
if(string::npos != textWords[i].find(bannedWords[j]))
{
textWords[i] = "***";
}
}
}
这只是一个固定数量的*取代,但我想它来代替它与*不是全字匹配的字符。
在此先感谢
你看过正则表达式(正则表达式)吗? – Tim 2012-03-07 15:31:58
你可以发布'textWords'和'bannedWords'的声明吗? – hmjd 2012-03-07 15:32:08
@hmjd我修改了我的帖子以显示声明。 – bobthemac 2012-03-07 15:34:07