65.9K
CodeProject is changing. Read more.
Home

String.Format equivalent for ASP

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.20/5 (10 votes)

Dec 2, 2008

CPOL
viewsIcon

52960

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!

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"))