「C#でUrlEncodeとUrlDecode」の版間の差分
imported>Administrator ページの作成:「C#というか.NETにはUrlEncodeとUrlDecodeの統一的な方法がない。標準的に行う方法は、バージョンごと、プラットフォームごとに方...」 |
imported>Administrator 編集の要約なし |
||
| 1行目: | 1行目: | ||
C#というか.NETにはUrlEncodeとUrlDecodeの統一的な方法がない。標準的に行う方法は、バージョンごと、プラットフォームごとに方法が異なりすぎて悲惨なことになっている。<syntaxhighlight lang="csharp"> | C#というか.NETにはUrlEncodeとUrlDecodeの統一的な方法がない。標準的に行う方法は、バージョンごと、プラットフォームごとに方法が異なりすぎて悲惨なことになっている。 | ||
<syntaxhighlight lang="csharp"> | |||
public static string UrlEncode( string s , Encoding enc ) | public static string UrlEncode( string s , Encoding enc ) | ||
{ | { | ||
var rt = new StringBuilder(); | |||
foreach ( byte i in enc.GetBytes( s ) ) | foreach ( byte i in enc.GetBytes( s ) ) | ||
{ | { | ||
| 23行目: | 25行目: | ||
} | } | ||
</syntaxhighlight> | |||
<syntaxhighlight lang="csharp"> | |||
public static string UrlDecode( string s , Encoding enc ) | public static string UrlDecode( string s , Encoding enc ) | ||
{ | { | ||
var bytes = new List<byte>(); | |||
for ( int i = 0; i < s.Length; i++ ) | for ( int i = 0; i < s.Length; i++ ) | ||
{ | { | ||