• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET UnicodeEncoding.GetDecoder方法代码示例发布时间:2022-05-24
下一篇:
VB.NET ASCIIEncoding.GetCharCount方法代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap