Encode a range of elements from a Unicode character array and store the encoded bytes in a range of elements in a byte array. : Unicode « I18N Internationalization « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » I18N Internationalization » Unicode 
21.15.7.Encode a range of elements from a Unicode character array and store the encoded bytes in a range of elements in a byte array.
using System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main() {
        Byte[] bytes;
        Char[] chars = new Char[] {
            '\u0023'// #
            '\u0025'// %
            '\u03a0'// Pi
            '\u03a3'  // Sigma
        };

        UnicodeEncoding Unicode = new UnicodeEncoding();

        int byteCount = Unicode.GetByteCount(chars, 12);
        bytes = new Byte[byteCount];
        int bytesEncodedCount = Unicode.GetBytes(chars, 12, bytes, 0);

        Console.WriteLine(bytesEncodedCount);

        foreach (Byte b in bytes) {
            Console.WriteLine(b);
        }
    }
}
21.15.Unicode
21.15.1.Create and write a string containing the symbol for Pi
21.15.2.Use GetByteCount to return the number of bytes required to encode an array of Unicode characters, using UTF8Encoding.
21.15.3.Unicode Encoding Example
21.15.4.Decode a range of elements from a byte array and store them in a Unicode character array
21.15.5.Unicode Encoding Example
21.15.6.List the Unicode code point of each of the control characters.
21.15.7.Encode a range of elements from a Unicode character array and store the encoded bytes in a range of elements in a byte array.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.