ARTICLE

Format String in VB.NET

Posted by Mahesh Chand Articles | Strings, Arrays in VB.NET August 25, 2010
This code snippet shows how to format strings in VB.NET.
 
Reader Level:

You can use the Format method to create formatted strings and concatenate multiple strings representing multiple objects. The Format method automatically converts any passed object into a string.

For example, the following code uses integer, floating number and string values and format them into a string using the Format method.

Listing 1: Using Format method to format a string

    Module Module1
        Sub Main()
            Dim val As Integer = 7
            Dim name As String = "Mr. John"
            Dim num As Single = 45.06F
            Dim str As String = [String].Format("Days Left : {0}. Current DataTime: {1:u}. " & vbLf & " String: {2}, Float: {3}", val, DateTime.Now, name, num)
            Console.WriteLine(str)
            Console.ReadLine()
        End Sub
    End
Module

Output

FS1.gif

Conclusion

Hope this article would have helped you in understanding Format Strings in VB.NET.

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor