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


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

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


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

示例1: Sample

' 导入命名空间
Imports System.Text

Class Sample
   '                                 index: 012345
   Private Shared initialValue As String = "--[]--"
   Private Shared sb As StringBuilder
   
   Public Shared Sub Main()
      Dim xyz As String = "xyz"
      Dim abc As Char() =  {"a"c, "b"c, "c"c}
      Dim star As Char = "*"c
      Dim obj As [Object] = 0
      
      Dim xBool As Boolean = True
      Dim xByte As Byte = 1
      Dim xInt16 As Short = 2
      Dim xInt32 As Integer = 3
      Dim xInt64 As Long = 4
      Dim xDecimal As [Decimal] = 5
      Dim xSingle As Single = 6.6F
      Dim xDouble As Double = 7.7
      
      ' The following types are not CLS-compliant.
      ' Dim xUInt16 As System.UInt16 = 8 
      ' Dim xUInt32 As System.UInt32 = 9
      ' Dim xUInt64 As System.UInt64 = 10 
      ' Dim xSByte As System.SByte = - 11
      '
      Console.WriteLine("StringBuilder.Insert method")
      sb = New StringBuilder(initialValue)
      
      sb.Insert(3, xyz, 2)
      Show(1, sb)
      
      sb.Insert(3, xyz)
      Show(2, sb)
      
      sb.Insert(3, star)
      Show(3, sb)
      
      sb.Insert(3, abc)
      Show(4, sb)
      
      sb.Insert(3, abc, 1, 2)
      Show(5, sb)
      
      sb.Insert(3, xBool)     ' True
      Show(6, sb)
      
      sb.Insert(3, obj)       ' 0
      Show(7, sb)
      
      sb.Insert(3, xByte)     ' 1
      Show(8, sb)
      
      sb.Insert(3, xInt16)    ' 2
      Show(9, sb)
      
      sb.Insert(3, xInt32)    ' 3
      Show(10, sb)
      
      sb.Insert(3, xInt64)    ' 4
      Show(11, sb)
      
      sb.Insert(3, xDecimal)  ' 5
      Show(12, sb)
      
      sb.Insert(3, xSingle)   ' 6.6
      Show(13, sb)
      
      sb.Insert(3, xDouble)   ' 7.7
      Show(14, sb)
      
      ' The following Insert methods are not CLS-compliant.
      ' sb.Insert(3, xUInt16) ' 8
      ' sb.Insert(3, xUInt32) ' 9
      ' sb.Insert(3, xUInt64) ' 10
      ' sb.Insert(3, xSByte)  ' -11

   End Sub
   
   Public Shared Sub Show(overloadNumber As Integer, sbs As StringBuilder)
      Console.WriteLine("{0,2:G} = {1}", overloadNumber, sbs.ToString())
      sb = New StringBuilder(initialValue)
   End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Text,代码行数:87,代码来源:StringBuilder.Insert

输出:

StringBuilder.Insert method
1 = --[xyzxyz]--
2 = --[xyz]--
3 = --[*]--
4 = --[abc]--
5 = --[bc]--
6 = --[True]--
7 = --[0]--
8 = --[1]--
9 = --[2]--
10 = --[3]--
11 = --[4]--
12 = --[5]--
13 = --[6.6]--
14 = --[7.7]--

示例2: MainClass

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

Public Class MainClass

   Shared Sub Main()
      Dim objectValue As Object = "hello"
      Dim stringValue As String = "good bye"
      Dim characterArray As Char() = {"a"c, "b"c, "c"c, _
         "d"c, "e"c, "f"c}

      Dim booleanValue As Boolean = True
      Dim characterValue As Char = "K"c
      Dim integerValue As Integer = 7
      Dim longValue As Long = 1123456
      Dim singleValue As Single = 2234.4325
      Dim doubleValue As Double = 33.3
      Dim buffer As StringBuilder = New StringBuilder()

      ' insert values into buffer
      buffer.Insert(0, objectValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, stringValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, characterArray)
      buffer.Insert(0, "  ")
      buffer.Insert(0, booleanValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, characterValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, integerValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, longValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, singleValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, doubleValue)
      buffer.Insert(0, "  ")

      Console.WriteLine("buffer after inserts:" & vbCrLf & _
         buffer.ToString() )

      buffer.Remove(12, 1)
      buffer.Remove(2, 4) 

      Console.WriteLine("buffer after Removes:" & vbCrLf & _
         buffer.ToString())

  End Sub ' Main

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


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