Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Общие вопросы по .NET и C# > Про кодировку


Автор: ldk13 26.7.2009, 18:30
Научил программку с помощью библиотеки taglib-sharp выуживать название песни. С английскими символами все хорошо, но вот с русскими дела обстоят не очень. Так вот родился такой вопрос: Можно ли в переменной string, имея  кусок текста узнать его кодировку?

Автор: wester 26.7.2009, 19:49
в String просто хранятся символы , Unicode символы 


как вариант попробуй использовать Encoding.Convert();

Автор: ldk13 26.7.2009, 20:02
ясно

А каким образом можно кодировку поменять строки?

Автор: wester 26.7.2009, 20:15
в msdn все расписано по шагам...... 

Код

string unicodeString = "This string contains the unicode character Pi(\u03a0)";

            // 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);

оттуда и код

Автор: ldk13 26.7.2009, 21:21
спасибо.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)