Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VBScript

String.Format equivalent for ASP

4.20/5 (11 votes)
2 Dec 2008CPOL 52.9K  
VBScript/ASP version of C# String.format(this {0} a {1},is,test).

Introduction

This is a String.Format equivalent function for classic ASP.

Background

I am working on an old ASP classic application (fixing bugs etc.). Have to say, I still love traditional classic ASP.

It takes moments to do something that would normally take hours in .NET; plus, it always feels so much faster to execute =)

Anyway, I needed a function similar to String.Format in C#. I could not find anything on Google, so I created my own and thought I would share.

Using the code

The code speaks for itself I think!

VBScript
Function StringFormat(sVal, aArgs)
Dim i
    For i=0 To UBound(aArgs)
        sVal = Replace(sVal,"{" & CStr(i) & "}",aArgs(i))
    Next
    StringFormat = sVal
End Function

StringFormat("this {0} a tes{1} string containing {2} values", _
             Array("is","t","some"))

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)