How to convert Integer to String using VB.NET

You can easily convert integer to string or string to integer. There are many way to convert integer to string.
  • 38827
Download Files:

You can easily convert integer to string  or string to integer. There are many way to convert integer to string.

String.Format() is static method. int.ToString() is an instance of method. It will throw NULL Reference Exception when you handling NULL value. Convert.ToString(). It will not throw any exception it can handle NULL value. String.Empty & integer initialized field at run time. StringBuilder().Append(integer).ToString() append the string value of the argument to this string builder.


Imports System.Text
Module Module1
    Sub Main()
        Console.WriteLine("Enter any number that you want to convert into string")
        Dim n1 As Integer = Int32.Parse(Console.ReadLine())
        Console.WriteLine("There are five way to convert into to string")
        Dim s1 As String = n1.ToString()
        Console.WriteLine("1. integer.ToString() method " & vbLf & "Output : " & s1)
        Dim s2 As String = Convert.ToString(n1)
        Console.WriteLine("2. Convert.ToString(integer) method " & vbLf & "Output :" & s2 & vbLf)
        Dim s3 As String = String.Format("{0}", n1)
        Console.WriteLine("3. string.Format(""{0}"",integer) method " & vbLf & "Output : " & s3 & vbLf)
        Dim s4 As String = String.Empty & n1
        Console.WriteLine("4. string.Empty + integer method " & vbLf & "Output : " & s4 & vbLf)
        Dim s5 As String = New StringBuilder().Append(n1).ToString()
        Console.WriteLine("5. StringBuilder().Append(integer).ToString() method " & vbLf & "Output : " & s5
         & vbLf)
    End Sub
End Module




More Articles

© 2019 DotNetHeaven. All rights reserved.