VB.Net/Development/String Format — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:40, 26 мая 2010

Double number format: 0:n3

 
Imports System
Public Class MainClass
    Shared Sub Main()
        "Declare variable
        Dim dblNumber As Double
        "Set number, divide numbers, and display results
        dblNumber = 45.34
        dblNumber /= 4.333
        System.Console.WriteLine("Division test... " & dblNumber)
        System.Console.WriteLine("With formatting: " & String.Format("{0:n3}", dblNumber))
    End Sub
End Class


Proper Title Case

  
Public Class MainClass
    Public Shared Function ProperCase(ByVal Text As String) As String
        Dim objCulture As New System.Globalization.CultureInfo("en-US")
        Return objCulture.TextInfo.ToTitleCase(Text.ToLower)
    End Function
    Public Shared Sub Main
        System.Console.WriteLine(ProperCase("this Is a Test"))
    End Sub
End Class


String Format: Currency

 
Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
      Dim amount, principal As Decimal " dollar amounts
      Dim rate As Double               " interest rate
      Dim year As Integer              " year counter
      Dim output As String             " amount after each year
      principal = 1000
      rate = 0.05
      output = "Year" & vbTab & "Amount on deposit" & vbCrLf
      " calculate amount after each year
      For year = 1 To 10
         amount = principal * (1 + rate) ^ year
         output &= year & vbTab & _
            String.Format("{0:C}", amount) & vbCrLf
      Next
      " display output
      Console.WriteLine("Compound Interest" & output)
    End Sub
    
End Class