Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi, i am running a program that wants to format and in order to do so i need to use format string.

Basically what i have is this:
VB
Dim fmtStr As String = "{0,-5} {1,7} {2,8}"
        ListBox1.Items.Add(txtItems.Text & "          Quantity: " & txtQty.Text & "          $" & Amount)


What i want is to make the below txt(txtItems, txtQty to work with the format string? How do i do so?
Posted

1 solution

The Format static method of String class can be used for this purpose as shown below:
C#
Dim fmtStr As String = String.Format("{0,-5}         Quantity: {1,7}    ${2,8}",
    txtItems.Text,txtQty.Text, Amount)

I think {2,8:C} can be used instead of ${2,8} in the above format string, to prefix the Currency symbol of Current culture
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 22-Apr-12 21:42pm    
A real help to OP with broken MSDN. :-)
My 5.
--SA
VJ Reddy 22-Apr-12 21:48pm    
Thank you, SA.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900