Formulir Kontak

Nama

Email *

Pesan *

Cari Blog Ini

Unicode To Char C

How to Display Characters in C#

Using NET's Character Conversion Classes

Converting Strings to Characters

To display the actual character value of a string, you can use the System.Text.Encoding class. The Encoding.Convert method converts a byte array to a character array, and the Encoding.GetString method converts a byte array to a string. For example, the following code converts the string "Hello" to a character array:

```csharp byte[] bytes = Encoding.ASCII.GetBytes("Hello"); char[] chars = Encoding.Convert(bytes, Encoding.ASCII, Encoding.Unicode); string str = new string(chars); ```

Using the Char Type

The System.Char type represents a single Unicode character. You can create a Char object by specifying the character value as an argument to the Char constructor, or by using the Char.Parse method. For example, the following code creates a Char object for the character 'A':

```csharp Char c = 'A'; ```

Using an Encoding Object

The System.Text.Encoding class provides a way to encode and decode character data. You can use an Encoding object to convert a byte array to a character array, or a character array to a byte array. For example, the following code uses an Encoding object to convert the string "Hello" to a byte array:

```csharp byte[] bytes = Encoding.UTF8.GetBytes("Hello"); ```


Komentar