ARTICLE

Different method to convert Char to String in vb.net

Posted by Sapna Articles | Visual Basic Language July 01, 2011
You can easily convert Unicode character to its equivalent string using below code.
Download Files:
 
Reader Level:

You can not implicitly convert the value of specified Unicode character to its equivalent string representation. You need to convert a char value to a string reference in your vb.net program. I have used many way to convert char to string in this article. Most have got a problem with parsing char to string now you can use any below method to convert char to string that get rid of from this problem.

1.GIF

There are several ways to do this, with the clearest being the ToString virtual method.

Code:

Module Module1
    Sub Main()
        Dim Chr As Char = "W"c
        Dim myString As New String(Chr, 1)
        Console.WriteLine(vbTab & myString)
        Dim Chr2 As Char = "X"c
        Dim myString1 As String = Chr2.ToString()
        Console.WriteLine(vbTab & myString1)
        Dim Chr3 As Char = "Y"c
        Dim myString2 As String = Convert.ToString(Chr3)
        Console.WriteLine(vbTab & myString2)
        Dim Chr4 As Char = "Z"c
        Dim myString3 As String = New [String](New Char() {Chr4})
        Console.WriteLine(vbTab & myString3)
        Console.ReadLine()
    End Sub
End Module

Output:

output.gif

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor