Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Delphi, .NET, Asm (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   C# , utf8 в cp1251 (https://forum.antichat.xyz/showthread.php?t=175867)

malik555 03.02.2010 15:15

C# , utf8 в cp1251
 
Всем привет !

Собственно вопрос как перекодировать строку utf8 в cp1251 и обратно , на C# ?

Желательно стандартными либами C# !

.ATK 03.02.2010 15:31

Цитата:

private string Win1251ToUTF8(string source)
{

Encoding utf8 = Encoding.GetEncoding("utf-8");
Encoding win1251 = Encoding.GetEncoding("windows-1251");

byte[] utf8Bytes = win1251.GetBytes(source);
byte[] win1251Bytes = Encoding.Convert(win1251, utf8, utf8Bytes);
source = win1251.GetString(win1251Bytes);
return source;

}

пиу


Время: 12:47