powered by simpleCommunicator - 2.0.59     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / cp-1251
2 сообщений из 2, страница 1 из 1
cp-1251
    #33051615
ks_ksm
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Как в тексте программы на C# перевести строку из Unicode в CP-1251.
...
Рейтинг: 0 / 0
cp-1251
    #33052927
Фотография profil
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
копать в следующем направлении:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003JUL.1033/cpref/html/frlrfsystemtextencodingclasstopic.htm
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
using System;
using System.Text;

namespace ConvertExample
{
   class ConvertExampleClass
   {
      static void Main()
      {
         string unicodeString = "This string contains the unicode character Pi(Π)";

         // Create two different encodings.
         Encoding ascii = Encoding.ASCII;
         Encoding unicode = Encoding.Unicode;

         // Convert the string into a byte[].
         byte[] unicodeBytes = unicode.GetBytes(unicodeString);

         // Perform the conversion from one encoding to the other.
         byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
            
         // Convert the new byte[] into a char[] and then into a string.
         // This is a slightly different approach to converting to illustrate
         // the use of GetCharCount/GetChars.
         char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
         ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
         string asciiString = new string(asciiChars);

         // Display the strings created before and after the conversion.
         Console.WriteLine("Original string: {0}", unicodeString);
         Console.WriteLine("Ascii converted string: {0}", asciiString);
      }
   }
}

+ для получения кодировки 1251:
Encoding e1251 = Encoding.GetEncoding(1251);
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / cp-1251
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]