加入 CodeStore VBA 模組
This commit is contained in:
1 parent
9c5364f88e
commit
0e638bdd15
22 files changed
+4510
No files matched your search
@@ -0,0 +1,46 @@
|
||||
Attribute VB_Name = "StringBuilder"
|
||||
Option Compare Text
|
||||
Option Explicit
|
||||
|
||||
Dim MyBuffer() As String
|
||||
Dim MyCurrentIndex As Long
|
||||
Dim MyMaxIndex As Long
|
||||
|
||||
Private Sub Class_Initialize()
|
||||
|
||||
Clear
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub Clear()
|
||||
MyCurrentIndex = 0
|
||||
MyMaxIndex = 16
|
||||
ReDim MyBuffer(1 To MyMaxIndex)
|
||||
End Sub
|
||||
|
||||
'Appends the given Text to this StringBuilder
|
||||
Public Sub Append(Text As String)
|
||||
|
||||
MyCurrentIndex = MyCurrentIndex + 1
|
||||
|
||||
If MyCurrentIndex > MyMaxIndex Then
|
||||
MyMaxIndex = 2 * MyMaxIndex
|
||||
ReDim Preserve MyBuffer(1 To MyMaxIndex)
|
||||
End If
|
||||
MyBuffer(MyCurrentIndex) = Text
|
||||
|
||||
End Sub
|
||||
|
||||
'Returns the text in this StringBuilder
|
||||
'Optional Parameter: Separator (default vbNullString) used in joining components
|
||||
Public Function ToString(Optional Separator As String = vbNullString) As String
|
||||
|
||||
If MyCurrentIndex > 0 Then
|
||||
ReDim Preserve MyBuffer(1 To MyCurrentIndex)
|
||||
MyMaxIndex = MyCurrentIndex
|
||||
ToString = Join(MyBuffer, Separator)
|
||||
End If
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
Reference in new issue
Block a user