如何解码C ++中的HTML实体? [英] How can I decode HTML entities in C++?
本文介绍了如何解码C ++中的HTML实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何解读C ++中的HTML实体?
How can I decode HTML entities in C++?
例如:
HTML:& quot ;音乐& & amp; & quot; video& quot;
HTML: "Music" & "video"
解码:音乐 & video
Decoded: "Music" & "video"
感谢。
推荐答案
使用C字符串感觉舒适,您可能对我的答案感兴趣 a>到类似的问题。
If you're comfortable with using C-strings, you might be interested in my answer to a similar question.
无需将代码编译为C ++:compile entities.c 作为
-std = c99
并链接对象文件与您的C ++代码,例如,如果你有下面的示例程序 foo.cpp
There's no need to compile the code as C++: compile entities.c
as -std=c99
and link the object file with your C++ code, eg if you have the follwing example program foo.cpp
#include <iostream>
extern "C" size_t decode_html_entities_utf8(char *dest, const char *src);
int main()
{
char line[100];
std::cout << "Enter encoded line: ";
std::cin.getline(line, sizeof line);
decode_html_entities_utf8(line, 0);
std::cout << line;
return 0;
}
使用
g++ -o foo foo.cpp entities.o
这篇关于如何解码C ++中的HTML实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文