什么c#桌面应用程序编码方法编码以匹配此编码
我正在尝试对以下字符串进行编码以构建URL 字符串:什么c#桌面应用程序编码方法编码以匹配此编码,c#,C#,我正在尝试对以下字符串进行编码以构建URL 字符串: 无线电信号加布里埃尔·莫雷斯,费尔南多·德·萨雷斯 对该网站上的字符串进行编码可提供: Radio%20Signal%20Gabriel%20Moraes%2Cfernando%20De%20S%C3%A1 当我试图用C语言模拟这种编码时,我似乎找不到一种方法来实现它 HttpUtility.urlpath编码(str)提供: Radio+Signal+Gabriel+Moraes%2CFernando+de+S%E1 Uri.EscapeD
无线电信号加布里埃尔·莫雷斯,费尔南多·德·萨雷斯
对该网站上的字符串进行编码可提供:
Radio%20Signal%20Gabriel%20Moraes%2Cfernando%20De%20S%C3%A1
当我试图用C语言模拟这种编码时,我似乎找不到一种方法来实现它
HttpUtility.urlpath编码(str)代码>提供:
Radio+Signal+Gabriel+Moraes%2CFernando+de+S%E1
Uri.EscapeDataString(str)代码>提供:
Radio+Signal+Gabriel+Moraes%2CFernando+de+S%E1
Uri.EscapeUriString(str)代码>提供:
Radio+Signal+Gabriel+Moraes%2CFernando+de+S%E1
HttpUtility.UrlEncode(str)代码>提供:
Radio+Signal+Gabriel+Moraes%2CFernando+de+S%E1
HttpUtility.UrlEncode(str,Encoding.UTF8)代码>
Radio+Signal+Gabriel+Moraes%2CFernando+de+S%E1
urlencoder网站上返回的编码结果适用于我正在尝试使用的网站,而其他网站则不适用
在.NET 4.5桌面框架中是否有一种C#方法可以执行与urlencoder网站相同的编码?我不确定您是如何得到您所做的结果的,但一个简单的测试表明,您计算出的选项之一完全符合您的要求
我设置的简单测试:
const string expected = "Radio%20Signal%20Gabriel%20Moraes%2Cfernando%20De%20S%C3%A1";
string input = "Radio Signal Gabriel Moraes,fernando De Sá";
var functionDict = new Dictionary<string, Func<string, string>>()
{
{ "HttpUtility.UrlPathEncode", x => HttpUtility.UrlPathEncode(x) },
{ "Uri.EscapeDataString", x => Uri.EscapeDataString(x) },
{ "Uri.EscapeUriString", x => Uri.EscapeUriString(x) },
{ "HttpUtility.UrlEncode", x => HttpUtility.UrlEncode(x) }
};
Console.WriteLine("Functions that match expected output:");
foreach(var f in functionDict)
{
string result = f.Value(input);
if(string.Compare(result, expected) == 0)
{
Console.WriteLine(f.Key);
}
}
const string expected=“无线电%20Signal%20Gabriel%20Moraes%2Cfernando%20De%20S%C3%A1”;
字符串输入=“无线电信号加布里埃尔·莫雷斯,费尔南多·德·萨瓦”;
var functionDict=新字典()
{
{“HttpUtility.urlpathcode”,x=>HttpUtility.urlpathcode(x)},
{“Uri.EscapeDataString”,x=>Uri.EscapeDataString(x)},
{“Uri.EscapeUriString”,x=>Uri.EscapeUriString(x)},
{“HttpUtility.UrlEncode”,x=>HttpUtility.UrlEncode(x)}
};
WriteLine(“与预期输出匹配的函数:”);
foreach(functionDict中的变量f)
{
字符串结果=f.值(输入);
if(string.Compare(结果,预期)==0)
{
控制台写入线(f键);
}
}
这将提供以下输出:
与预期输出匹配的函数:
Uri.EscapeDataString
所以我想也许你应该再看看
Fiddle我不确定你是如何得到你所做的结果的,但一个简单的测试表明,你计算出来的选项中有一个正是你想要的
我设置的简单测试:
const string expected = "Radio%20Signal%20Gabriel%20Moraes%2Cfernando%20De%20S%C3%A1";
string input = "Radio Signal Gabriel Moraes,fernando De Sá";
var functionDict = new Dictionary<string, Func<string, string>>()
{
{ "HttpUtility.UrlPathEncode", x => HttpUtility.UrlPathEncode(x) },
{ "Uri.EscapeDataString", x => Uri.EscapeDataString(x) },
{ "Uri.EscapeUriString", x => Uri.EscapeUriString(x) },
{ "HttpUtility.UrlEncode", x => HttpUtility.UrlEncode(x) }
};
Console.WriteLine("Functions that match expected output:");
foreach(var f in functionDict)
{
string result = f.Value(input);
if(string.Compare(result, expected) == 0)
{
Console.WriteLine(f.Key);
}
}
const string expected=“无线电%20Signal%20Gabriel%20Moraes%2Cfernando%20De%20S%C3%A1”;
字符串输入=“无线电信号加布里埃尔·莫雷斯,费尔南多·德·萨瓦”;
var functionDict=新字典()
{
{“HttpUtility.urlpathcode”,x=>HttpUtility.urlpathcode(x)},
{“Uri.EscapeDataString”,x=>Uri.EscapeDataString(x)},
{“Uri.EscapeUriString”,x=>Uri.EscapeUriString(x)},
{“HttpUtility.UrlEncode”,x=>HttpUtility.UrlEncode(x)}
};
WriteLine(“与预期输出匹配的函数:”);
foreach(functionDict中的变量f)
{
字符串结果=f.值(输入);
if(string.Compare(结果,预期)==0)
{
控制台写入线(f键);
}
}
这将提供以下输出:
与预期输出匹配的函数:
Uri.EscapeDataString
所以我想也许你应该再看看
小提琴+
和%20
可以互换+
是一个特殊的空格字符%20
是空格字符的ASCII值。您如何测量输出?这些结果字符串来自何处?+
和%20
可以互换+
是一个特殊的空格字符%20
是空格字符的ASCII值。您如何测量输出?这些结果字符串从何而来?很好的工作,但实际上应该是一场势均力敌的投票。“这个问题是由一个无法再复制的问题或一个简单的印刷错误引起的。”@spender I在接近投票时迟到了。你完全正确!在执行路径中有另一个我没有看到的UrlEncode。逃逸就是那个。非常感谢。干得好,但实际上这应该是一场势均力敌的投票。“这个问题是由一个无法再复制的问题或一个简单的印刷错误引起的。”@spender I在接近投票时迟到了。你完全正确!在执行路径中有另一个我没有看到的UrlEncode。逃逸就是那个。非常感谢。