如何将多个空格压缩为单个/删除所有空格?请参阅以下源代码和示例输入。
void walkTree(xmlNode * a_node) {
xmlNode *cur_node = NULL;
for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_TEXT_NODE) {
printf("%s", cur_node->content);
}
walkTree(cur_node->children);
}
}
void main () {
htmlParserCtxtPtr parser = htmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL, 0);
htmlCtxtUseOptions(parser, HTML_PARSE_NOBLANKS | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET);
len = ReadFile(data);
htmlParseChunk(parser, data, len, 0);
walkTree(xmlDocGetRootElement(parser->myDoc));
}
input: "<table><tbody><tr><td><b>Updated by:</b> </td><td >Test</td></tr></tbody></table><br/>"
output: "Updated by: Test"
感谢。
答案 0 :(得分:0)
尝试使用此功能:
str.erase(remove_if(str.begin(), str.end(), isspace), str.end());