Encoding Class represents a character encoding. : String « Data Types « VB.Net

Encoding Class represents a character encoding.


Imports System
Imports System.Text
Imports Microsoft.VisualBasic

    Class MyConvertExampleClass
        Shared Sub Main()
            Dim unicodeString As String = "Pi:" & ChrW(&H03A0)

            Dim ascii As Encoding = Encoding.ASCII
            Dim [unicode] As Encoding = Encoding.Unicode

            Dim unicodeBytes As Byte() = [unicode].GetBytes(unicodeString)

            Dim asciiBytes As Byte() = Encoding.Convert([unicode], ascii, unicodeBytes)

            Dim asciiChars(ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)-1) As Char
            ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0)
            Dim asciiString As New String(asciiChars)

            Console.WriteLine("Original string: {0}", unicodeString)
            Console.WriteLine("Ascii converted string: {0}", asciiString)
        End Sub
    End Class


Related examples in the same category

1.String Object: =, Is and MidString Object: =, Is and Mid
2.String InStrString InStr
3.String InsertString Insert
4.Use the Mid function to replace within the stringUse the Mid function to replace within the string
5.Use String.Equals methodsUse String.Equals methods
6.Two ways to copy stringsTwo ways to copy strings
7.Two ways to concatenate stringsTwo ways to concatenate strings
8.Sub string with only one parameter
9.String PadLeftString PadLeft
10.String ConstructorString Constructor
11.String properties Length and Chars and method CopyTo of class StringString properties Length and Chars and method CopyTo of class String
12.Comparing stringsComparing strings
13.Demonstrating StartsWith and EndsWith methodsDemonstrating StartsWith and EndsWith methods
14.String Substring methodString Substring method
15.String class Concat methodString class Concat method
16.String ToLower and ToUpperString ToLower and ToUpper
17.String Trim methodString Trim method
18.String ToString methodString ToString method
19.String ToCharArray method String ToCharArray method
20.Concatenate the strings and display the resultsConcatenate the strings and display the results
21.The length of the stringThe length of the string
22.Display the first part of a string
23.String: set value and display
24.Concatenate the stringsConcatenate the strings
25.Display the length of the stringDisplay the length of the string
26.Get sub stringGet sub string
27.Replace the string occuranceReplace the string occurance
28.String Replace DemoString Replace Demo
29.Concatenate String with Integer into one StringConcatenate String with Integer into one String
30.Concatenate StringsConcatenate Strings
31.String CopyString Copy
32.String.Equals DemoString.Equals Demo
33.Convert to Upper case and Lower CaseConvert to Upper case and Lower Case
34.Trim String spaceTrim String space
35.String ends withString ends with
36.String concatenation
37.Create a string that consists of a character repeated 20 times
38.Append Date string to existing string
39.Extract the second word
40.String Class Represents text as a series of Unicode characters.
41.Create a string from a character array
42.Create a string that consists of a character repeated 20 times
43.Format Date with D
44.Append string together
45.Format a DateTime
46.Is Surrogate Pair
47.Is Punctuation and Is WhiteSpace
48.Create StreamWriter for Unicode encoding
49.Format Date by different Culture
50.Parse String to Date with various Culture settings
51.Perform a word sort using the current (en-US) culture
52.Perform a word sort using the invariant culture
53.Perform an ordinal sort
54.Perform a string sort using the current culture
55.Find string with different StringComparison
56.Culture-sensitive test for equality
57.Ordinal test for equality
58.String.Format Method (IFormatProvider, String, Object[])
59.Format Date with different Culture
60.StringBuilder Class Represents a mutable string of characters
61.CultureInfo Class provides information about a specific culture
62.CultureInfo's English Name and
63.CultureInfo.CurrentCulture Property gets the CultureInfo that represents the culture used by the current thread.
64.String.Chars Property gets the Char object at a specified position in the current String object.
66.String.Contains Method returns a value indicating whether the specified String object occurs within this string.
68.String.CopyTo Method
69.String.EndsWith (String, StringComparison)
70.String.Equals Method
71.String.Equals (String)
72.String.Format (IFormatProvider, String, Object[])
73.Customer Formatter
74.String.Format Method (String, Object)
75.String.Format (String, Object, Object)
77.String.GetHashCode Method
78.String.GetTypeCode Method returns the TypeCode for class String.
79.Sample for String.Intern(String)
81.String.Join Method
82.Concatenates the members of a collection, using the specified separator between each member.
83.String.Length Property gets the number of characters in the current String object.
84.String.PadLeft Method (Int32)
85.String.PadLeft Method (Int32, Char)
87.String.PadRight Method (Int32, Char)
89.Deletes a specified number of characters from this instance beginning at a specified position.
90.String.Replace (Char, Char)
91.String.Replace (String, String)
92.Retrieves a substring
93.Retrieves a substring which starts at a specified character position and has a specified length.
94.Copies the characters to a Unicode character array.
95.Convert to lowercase according to Culture settings
96.Convert string to lowercase
97.Convert String to lowercase using the casing rules of the invariant culture.
99.String.ToUpper (CultureInfo)
101.Convert String to uppercase using the casing rules of the invariant culture.
102.Removes all leading and trailing occurrences of a set of characters
103.Removes all leading and trailing white-space characters from the current String object.
104.Removes all trailing occurrences of a set of characters
105.Encode the original string using the ASCII encoder
106.CharEnumerator Class supports iterating over a String