String.Format("My name is {0}", "Luciano Evaristo Guerche") (VB6)

A feature I loved in .NET (C# and VB.NET) is String.Format method. So I thought how I could have the same feature on VB6 and I came up with the following code.

Public Function StringDotFormat(ByVal strFormat As String, ByVal ParamArray aryPlaceHolders()) As String

Dim intPlaceHolderIndex As Integer

Dim strOutput As String

 

strOutput = strFormat

 

For intPlaceHolderIndex = LBound(aryPlaceHolders) To UBound(aryPlaceHolders)

strOutput = Replace(strOutput, "{" & intPlaceHolderIndex & "}", aryPlaceHolders(intPlaceHolderIndex))

Next

 

StringDotFormat = strOutput

End Function

 

Then used it the following way

Call StringDotFormat("My name is {0}", "Luciano Evaristo Guerche")

 

What do you think about it? Drop me a comment and let me know your opinion.

5 Comments

Comments have been disabled for this content.