htmlencode和htmldecode,在线等待,比较急 在vc中如何实现象asp中的htmlencode和htmldecode,就是编码解码,请多帮忙。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用CString或者string,比如CString:void HtmlEncode(CString &sz){sz.Replace("<", "<");sz.Replace(">", ">");...}效果:输入:"The image tag: <img>",输出:"The image tag: <img>"其他编码方式类似实现,解码也是类似实现 #include <algorithm>#include <iostream>#include <string>#define array_length(array) (sizeof (array) / sizeof (array)[0])namespace Raye { using namespace std; struct HTMLReplace { string match; string replace; } codes[] = { {"&", "&"}, {"<", "<"}, {">", ">"} }; string HTMLEncode( const string& s ) { string rs = s; // Replace each matching token in turn for ( size_t i = 0; i < array_length( codes ); i++ ) { // Find the first match const string& match = codes[i].match; const string& repl = codes[i].replace; string::size_type start = rs.find_first_of( match ); // Replace all matches while ( start != string::npos ) { rs.replace( start, match.size(), repl ); // Be sure to jump forward by the replacement length start = rs.find_first_of( match, start + repl.size() ); } } return rs; }}int main(){ using namespace std; cout << Raye::HTMLEncode( "template <class T> void foo( const string& bar );" ) << '\n'; return 0;} 我脸上又没长朵花,为什么最近天天有人关注我啊? 画图的难题 网络编程问题 我喜欢MFC:写在《十年MFC经历认识的Microsoft技术》发表之后…… 关于单线程和多线程问题? 各位高手:想在屏幕上显示一段文本,计算矩形区域大小、将底色设置为浅黄色,文本设置为黑色,显示后如何消除这个区域,如何用API实现 求教VC高手:---------------有分送了!!!!!!!!!!!!!! 如何自己编写代码实现读取Event Log中的内容? 请问各位fft算法到底是什么?做什么用的? 还是要请各位大侠再帮帮我··谢谢谢谢了·· 结构体分配空间问题 xml数据可以当做数据库来用吗?
{
sz.Replace("<", "<");
sz.Replace(">", ">");
...
}效果:
输入:"The image tag: <img>",输出:"The image tag: <img>"
其他编码方式类似实现,解码也是类似实现
#include <algorithm>
#include <iostream>
#include <string>#define array_length(array) (sizeof (array) / sizeof (array)[0])namespace Raye {
using namespace std; struct HTMLReplace {
string match;
string replace;
} codes[] = {
{"&", "&"},
{"<", "<"},
{">", ">"}
}; string HTMLEncode( const string& s )
{
string rs = s; // Replace each matching token in turn
for ( size_t i = 0; i < array_length( codes ); i++ ) {
// Find the first match
const string& match = codes[i].match;
const string& repl = codes[i].replace;
string::size_type start = rs.find_first_of( match ); // Replace all matches
while ( start != string::npos ) {
rs.replace( start, match.size(), repl );
// Be sure to jump forward by the replacement length
start = rs.find_first_of( match, start + repl.size() );
}
} return rs;
}
}int main()
{
using namespace std; cout << Raye::HTMLEncode( "template <class T> void foo( const string& bar );" ) << '\n'; return 0;
}