bool ReplaceHtmlEscaped(string &strHtml)
{
const char *csEscapeMap[][2]={
{" "," "},
{"“","“"},
{"”","”"},
{""","\""},
{"—","—"},
{"
{">",">"},
{"&","&"},
{" ",""},
{" ",""},
{"\r",""},
{"\n",""},
{"\t",""}
};
int nEscapeMapSize = sizeof(csEscapeMap)/sizeof(csEscapeMap[0]);
//替换转义字符
for (int i=0; i
{
string::size_type nPos = 0;
while ( (nPos = strHtml.find(csEscapeMap[i][0], nPos)) != string::npos )
{
strHtml.replace( nPos, strlen(csEscapeMap[i][0]), csEscapeMap[i][1] );
}
}
return true;
}
发表后自动转码了,将数组第一列换成需要转换的转义字符比如
const char *csEscapeMap[][2]={ {" "," "}, {"“","“"}, {"”","”"}, {""","\""}, {"—","—"}, {"<",""}, {"&","&"}, {" ",""}, {" ",""}, {"\r",""}, {"\n",""}, {"\t",""} };