HTML URL 编码
时间: 2023-10-11 15:06:45 浏览: 48
HTML URL编码是一种将字符转换为特殊格式的编码方式,以便在URL中传输。常见的HTML URL编码包括:
1. %20表示空格
2. %23表示#
3. %26表示&
4. %2F表示/
5. %3F表示?
6. %3D表示=
7. %2B表示+
8. %40表示@
例如,将“Hello World!”转换为HTML URL编码后为“Hello%20World%21”。
相关问题
HTML URL 编码表
以下是常见字符的HTML URL编码表:
字符 | 编码
-----|-----
空格 | %20
! | %21
" | %22
# | %23
$ | %24
% | %25
& | %26
' | %27
( | %28
) | %29
* | %2A
+ | %2B
, | %2C
- | %2D
. | %2E
/ | %2F
0 | %30
1 | %31
2 | %32
3 | %33
4 | %34
5 | %35
6 | %36
7 | %37
8 | %38
9 | %39
: | %3A
; | %3B
< | %3C
= | %3D
> | %3E
? | %3F
@ | %40
A | %41
B | %42
C | %43
D | %44
E | %45
F | %46
G | %47
H | %48
I | %49
J | %4A
K | %4B
L | %4C
M | %4D
N | %4E
O | %4F
P | %50
Q | %51
R | %52
S | %53
T | %54
U | %55
V | %56
W | %57
X | %58
Y | %59
Z | %5A
[ | %5B
\ | %5C
] | %5D
^ | %5E
_ | %5F
` | %60
a | %61
b | %62
c | %63
d | %64
e | %65
f | %66
g | %67
h | %68
i | %69
j | %6A
k | %6B
l | %6C
m | %6D
n | %6E
o | %6F
p | %70
q | %71
r | %72
s | %73
t | %74
u | %75
v | %76
w | %77
x | %78
y | %79
z | %7A
{ | %7B
\ | %7C
} | %7D
~ | %7E
c++ HTML URL 编码表转化
以下是使用 C++ 实现将字符串中的特殊字符转换为 HTML URL 编码的示例代码:
```c++
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
string urlEncode(const string& str) {
ostringstream escaped;
escaped.fill('0');
escaped << hex;
for (string::const_iterator it = str.begin(), end = str.end(); it != end; ++it) {
string::value_type c = (*it);
// Keep alphanumeric and other accepted characters intact
if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
escaped << c;
}
// Any other characters are percent-encoded
else {
escaped << uppercase;
escaped << '%' << setw(2) << int((unsigned char)(c));
escaped << nouppercase;
}
}
return escaped.str();
}
int main() {
string str = "HTML URL 编码表";
string encodedStr = urlEncode(str);
cout << "转换前:" << str << endl;
cout << "转换后:" << encodedStr << endl;
return 0;
}
```
输出结果:
```
转换前:HTML URL 编码表
转换后:HTML%20URL%20%E7%BC%96%E7%A0%81%E8%A1%A8
```
可以看到,特殊字符被转换为了 HTML URL 编码形式。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)