CString 编码_url编码(const CString &要编码的文本) { CStringA tmp; tmp = 要编码的文本; std::string URL = tmp; CString 返回; for (unsigned int i = 0; i < URL.size(); i++) { char c = URL[i]; if (('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') /*|| c == '/'*/ || c == '.') //如果/也转,就去掉注释 { 返回 += c; }else { int j = (short int)c; if (j < 0) {j += 256;} int i1, i0; i1 = j / 16; i0 = j - i1 * 16; 返回 += '%'; if (0 <= i1 && i1 <= 9) {返回 += char(short('0') + i1);} else if (10 <= i1 && i1 <= 15) {返回 += char(short('A') + i1 - 10);} if (0 <= i0 && i0 <= 9) {返回 += char(short('0') + i0);} else if (10 <= i0 && i0 <= 15) {返回 += char(short('A') + i0 - 10);} } } return 返回; } 压缩版: CString 编码_url编码(const CString &要编码的文本) { CStringA tmp; tmp = 要编码的文本; std::string URL = tmp; CString 返回; for (unsigned int i = 0; i < URL.size(); i++) {char c = URL[i]; /*如果/也转,就去掉注释*/ if (('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') /*|| c == '/'*/ || c == '.') {返回 += c; }else {int j = (short int)c;if (j < 0) {j += 256;}int i1, i0; i1 = j / 16; i0 = j - i1 * 16; 返回 += '%'; if (0 <= i1 && i1 <= 9) {返回 += char(short('0') + i1);} else if (10 <= i1 && i1 <= 15) {返回 += char(short('A') + i1 - 10);} if (0 <= i0 && i0 <= 9) {返回 += char(short('0') + i0);} else if (10 <= i0 && i0 <= 15) {返回 += char(short('A') + i0 - 10);} } } return 返回; }