对URI编码字符串中的实际字符进行计数
本文关键字:字符 编码 URI 编码字符 字符串 | 更新日期: 2023-09-27 18:13:47
在客户端,我有一个textarea,我像这样提取它的值:
var TheURIEncodedString = encodeURI($('#TheTextArea').val());
字符串看起来像这样:
"This%20is%20a%20test%0AThis%20is%20a%20new%20line"
我通过ajax发送这个字符串,当我在服务器上收到它时,我需要计算实际字符的数量,而不是字符串的长度。
我该怎么做?
使用HtppUtility.UrlDecode
:
HttpUtility.UrlDecode("This%20is%20a%20test%0AThis%20is%20a%20new%20line").Length;
结果:This is a test
This is a new line
使用httputility。UrlDecode方法
int numberOfCharacters =
HttpUtility.UrlDecode("This%20is%20a%20test%0AThis%20is%20a%20new%20line").Length;