6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Excel VBA】コピペ用:簡易StringBuilder

Last updated at Posted at 2015-12-14

#前述
クラスモジュールを作ってコピペして使う。自分用。

インスタンス化して、 Append() で文字列追加。 AppendLine()で1行追加。 GetString() でAppendしてった文字列を取得する。機能はそれくらい。

Excel VBAでセルの内容を読み取って一文を作り上げるって時に、簡易的なStringBuilder的なクラスがあると便利だし、ソースを文字列結合式で埋めたくなかったので。
& でいっぱい文字列とか改行する為に Chr(13) & Chr(10)を結合するのもなんか汚く感じるし、なんか楽しくなかったので。

#ソース

SimpleStringBuilder
'====================================================================
' 簡易StringBuilder
'
'--------------------------------------------------------------------
' create: 2015/12/07
' update: 2015/12/07
'====================================================================
Option Explicit

'=========================================================
' メンバ宣言
'=========================================================
' 成形文字列
Private strString As String

' 改行コード
Private RTN_CODE As String

'=========================================================
' コンストラクタ
'=========================================================
Private Sub Class_Initialize()

    ' 初期化
    strString = ""
    RTN_CODE = Chr(13) & Chr(10)

End Sub

'=========================================================
' 成形した文字列を空文字にする
'=========================================================
Public Sub Clear()

    strString = ""

End Sub

'=========================================================
' 成形した文字列を取得する
'---------------------------------------------------------
' return                    成形した文字列
'=========================================================
Public Function GetString()

    GetString = strString

End Function

'=========================================================
' 文字列を追加
'---------------------------------------------------------
' param strAdd              追加する文字列
'=========================================================
Public Sub Append(ByVal strAdd)

    strString = strString & strAdd

End Sub

'=========================================================
' 文字列を追加
'---------------------------------------------------------
' param strAdd              追加する文字列
'=========================================================
Public Sub AppendLine(ByVal strAdd)

    Append (strAdd & RTN_CODE)
   
End Sub

#今後
あったら便利な機能とかあったら追加していきたいけど今のところ特に予定なし。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?