当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET StringBuilder.AppendFormat方法代码示例

本文整理汇总了VB.NET中System.Text.StringBuilder.AppendFormat方法的典型用法代码示例。如果您正苦于以下问题:VB.NET StringBuilder.AppendFormat方法的具体用法?VB.NET StringBuilder.AppendFormat怎么用?VB.NET StringBuilder.AppendFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.StringBuilder的用法示例。


在下文中一共展示了StringBuilder.AppendFormat方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Example

' 导入命名空间
Imports System.Globalization
Imports System.Text

Public Module Example
   Public Sub Main()
      Dim rnd As New Random()
      Dim culture As CultureInfo = CultureInfo.CreateSpecificCulture("fr-FR")
      Dim sb As New StringBuilder()
      Dim formatString As String = "    {0,12:N0} ({0,8:X8})" + vbCrLf +
                                   "And {1,12:N0} ({1,8:X8})" + vbCrLf +
                                   "  = {2,12:N0} ({2,8:X8})" + vbCrLf
      For ctr As Integer = 0 To 2
         Dim value1 As Integer = rnd.Next()
         Dim value2 As Integer = rnd.Next()
         sb.AppendFormat(culture, formatString,
                         value1, value2, value1 And value2).AppendLine()
      Next
      Console.WriteLine(sb.ToString())
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Text,代码行数:21,代码来源:StringBuilder.AppendFormat

输出:

1 984 112 195 (76432643)
And 1 179 778 511 (4651FDCF)
= 1 178 674 243 (46412443)

2 034 813 710 (7948CB0E)
And  569 333 976 (21EF58D8)
=  558 385 160 (21484808)

126 717 735 (078D8F27)
And 1 830 715 973 (6D1E8245)
=   84 705 797 (050C8205)

示例2: Sample

' 导入命名空间
Imports System.Text
Imports System.Globalization

Class Sample
   Private Shared sb As New StringBuilder()

   Public Shared Sub Main()
      Dim var1 As Integer = 111
      Dim var2 As Single = 2.22F
      Dim var3 As String = "abcd"
      Dim var4 As Object() =  {3, 4.4, "X"c}
      
      Console.WriteLine()
      Console.WriteLine("StringBuilder.AppendFormat method:")
      sb.AppendFormat("1) {0}", var1)
      Show(sb)
      sb.AppendFormat("2) {0}, {1}", var1, var2)
      Show(sb)
      sb.AppendFormat("3) {0}, {1}, {2}", var1, var2, var3)
      Show(sb)
      sb.AppendFormat("4) {0}, {1}, {2}", var4)
      Show(sb)
      Dim ci As New CultureInfo("es-ES", True)
      sb.AppendFormat(ci, "5) {0}", var2)
      Show(sb)
   End Sub
   
   Public Shared Sub Show(sbs As StringBuilder)
      Console.WriteLine(sbs.ToString())
      sb.Length = 0
   End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Text,代码行数:33,代码来源:StringBuilder.AppendFormat

输出:

StringBuilder.AppendFormat method:
1) 111
2) 111, 2.22
3) 111, 2.22, abcd
4) 3, 4.4, X
5) 2,22

示例3: Example

' 导入命名空间
Imports System.Globalization
Imports System.Text

Module Example
   Public Sub Main()
      Dim sb As New StringBuilder()
      Dim value As Decimal = 16.95d
      Dim enGB As CultureInfo = CultureInfo.CreateSpecificCulture("en-GB")
      Dim dateToday As DateTime = Date.Now
      sb.AppendFormat(enGB, "Final Price: {0:C2}", value)
      sb.AppendLine()
      sb.AppendFormat(enGB, "Date and Time: {0:d} at {0:t}", dateToday)
      Console.WriteLine(sb.ToString())
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Text,代码行数:16,代码来源:StringBuilder.AppendFormat

输出:

Final Price: £16.95
Date and Time: 01/10/2014 at 10:22

示例4: Customer

' 导入命名空间
Imports System.Text

Public Class Customer
   Private custName As String
   Private custNumber As Integer
   
   Public Sub New(name As String, number As Integer)
      custName = name
      custNumber = number
   End Sub
   
   Public ReadOnly Property Name As String
      Get
         Return Me.custName
      End Get
   End Property
   
   Public ReadOnly Property CustomerNumber As Integer
      Get
         Return Me.custNumber
      End Get
   End Property
End Class

Public Class CustomerNumberFormatter 
   Implements IFormatProvider, ICustomFormatter
   
   Public Function GetFormat(formatType As Type) As Object _
                   Implements IFormatProvider.GetFormat
      If formatType Is GetType(ICustomFormatter) Then
         Return Me
      End If
      Return Nothing
   End Function
   
   Public Function Format(fmt As String, arg As Object, provider As IFormatProvider) As String _
                   Implements ICustomFormatter.Format
      If typeof arg Is Int32 Then
         Dim custNumber As String = CInt(arg).ToString("D10")
         Return custNumber.Substring(0, 4) + "-" + custNumber.SubString(4, 3) + _
                "-" + custNumber.Substring(7, 3)
      Else
         Return Nothing
      End If
   End Function                   
End Class

Module Example
   Public Sub Main()
      Dim customer As New Customer("A Plus Software", 903654)
      Dim sb As New StringBuilder()
      sb.AppendFormat(New CustomerNumberFormatter, "{0}: {1}", _
                      customer.CustomerNumber, customer.Name)
      Console.WriteLine(sb.ToString())
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Text,代码行数:57,代码来源:StringBuilder.AppendFormat

输出:

0000-903-654: A Plus Software

示例5: Example

' 导入命名空间
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Text

Module Example
   Public Sub Main()
      Dim culture As New CultureInfo("en-US")
      Dim sb As New StringBuilder()
      Dim temperatureInfo As New Dictionary(Of Date, Double) 
      temperatureInfo.Add(#6/1/2010 2:00PM#, 87.46)
      temperatureInfo.Add(#12/1/2010 10:00AM#, 36.81)
      
      sb.AppendLine("Temperature Information:").AppendLine()
      For Each item In temperatureInfo
         sb.AppendFormat(culture,
                         "Temperature at {0,8:t} on {0,9:d}: {1,5:N1}°F",
                         item.Key, item.Value).AppendLine()
      Next
      Console.WriteLine(sb.ToString())
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Text,代码行数:22,代码来源:StringBuilder.AppendFormat

输出:

Temperature Information:

Temperature at  2:00 PM on  6/1/2010:  87.5°F
Temperature at 10:00 AM on 12/1/2010:  36.8°F

示例6: MainClass

' 导入命名空间
Imports System
Imports System.Text

Public Class MainClass
    
    Shared Sub Main()
             Dim s1 As String = "One,Two,Three www . java2s . com"

             Const Space As Char = " "c
             Const Comma As Char = ","c

             Dim delimiters(  ) As Char = {Space, Comma}

             Dim ctr As Integer = 0

             Dim resultArray As String(  ) = s1.Split(delimiters)

             Dim output As New StringBuilder(  )
             Dim subString As String
             For Each subString In resultArray
                 ctr = ctr + 1
                 output.AppendFormat("{0} : {1}" & _
                    Environment.NewLine, ctr, subString)
             Next subString
             Console.WriteLine(output.ToString(  ))
            
   End Sub

End Class
开发者ID:VB程序员,项目名称:System.Text,代码行数:30,代码来源:StringBuilder.AppendFormat


注:本文中的System.Text.StringBuilder.AppendFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。