计算URI编码字符串中的实际字符

时间:2013-05-16 10:54:30

标签: c#

在客户端上,我有一个textarea,我提取它的值如下:

var TheURIEncodedString = encodeURI($('#TheTextArea').val());

然后字符串如下所示:

"This%20is%20a%20test%0AThis%20is%20a%20new%20line"

我通过ajax发送这个字符串,当我在服务器上收到它时,我需要计算实际字符的数量,而不是字符串的长度。

我该怎么做?

2 个答案:

答案 0 :(得分:4)

使用HtppUtility.UrlDecode

HttpUtility.UrlDecode("This%20is%20a%20test%0AThis%20is%20a%20new%20line").Length;

结果:

This is a test
This is a new line

答案 1 :(得分:1)

使用HtppUtility.UrlDecode方法

int numberOfCharacters = 
    HttpUtility.UrlDecode("This%20is%20a%20test%0AThis%20is%20a%20new%20line").Length;