VBAのReplace()関数の代替関数
これも同様です。性能は、中くらい!
なので、これより、"VBScript.RegExp"のReplace()メソッドがお勧めです。
a = String(1024& * 1024&, "a")
t1 = Timer
b = Replacex(a, "a", "b")
Debug.Print Timer - t1
' 2.523438
Function Replacex(s, p, r)
Dim a() As String, n As Long, b As Long, e As Long, f As Long
ReDim a(Len(s))
b = 1
n = 0
f = InStr(b, s, p)
Do While f
a(n) = Mid(s, b, f - b)
n = n + 1
b = f + Len(p)
f = InStr(b, s, p)
Loop
a(n) = Mid(s, b)
ReDim Preserve a(n)
Replacex = Join(a, r)
End Function
« VBAのReplace()関数も、チョー遅い! | トップページ | VBScriptやVBAのSplit()関数も、チョー遅い! »