Click here to Skip to main content
11,481,404 members (65,933 online)
Click here to Skip to main content

Tagged as

String.Format equivalent for ASP

, 2 Dec 2008 CPOL 30.3K 17
Rate this:
Please Sign up or sign in to vote.
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"))

License

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

Share

About the Author

John Doherty
Chief Technology Officer MammothWorkwear.com
United Kingdom United Kingdom
Senior Web Developer, Systems Architect and Entrepreneur. Technical Director of MammothWorkwear.com. More information is available at http://www.johndoherty.info/

Comments and Discussions

 
GeneralGood insight Pin
Donsw13-Dec-08 8:08
memberDonsw13-Dec-08 8:08 
GeneralOther Methodologies to apply are always welcome... Pin
Tweellt10-Dec-08 5:27
memberTweellt10-Dec-08 5:27 
GeneralThanks for the snippet Pin
stylesie8-Dec-08 16:24
memberstylesie8-Dec-08 16:24 
GeneralRe: Thanks for the snippet Pin
bjahelka18-Dec-08 15:12
memberbjahelka18-Dec-08 15:12 
GeneralIt takes moments to do something that would normally take hours in .Net, plus it always feels so much faster to execute =) Pin
brianma8-Dec-08 13:50
memberbrianma8-Dec-08 13:50 
GeneralRe: It takes moments to do something that would normally take hours in .Net, plus it always feels so much faster to execute =) Pin
stylesie8-Dec-08 16:17
memberstylesie8-Dec-08 16:17 
GeneralThat can be done in just one line using RegEx Pin
Federico Colombo5-Dec-08 15:02
memberFederico Colombo5-Dec-08 15:02 
GeneralRe: That can be done in just one line using RegEx Pin
AndrewR738-Dec-08 7:25
memberAndrewR738-Dec-08 7:25 
GeneralSimilar to my printf Article Pin
Uwe Keim2-Dec-08 11:18
sitebuilderUwe Keim2-Dec-08 11:18 
GeneralRe: Similar to my printf Article Pin
John Doherty2-Dec-08 11:30
memberJohn Doherty2-Dec-08 11:30 
GeneralRe: Similar to my printf Article Pin
John Doherty2-Dec-08 11:36
memberJohn Doherty2-Dec-08 11:36 
GeneralMy vote of 2 Pin
rickoshay2-Dec-08 9:54
memberrickoshay2-Dec-08 9:54 
GeneralRe: My vote of 2 Pin
Gevorg3-Dec-08 5:59
memberGevorg3-Dec-08 5:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 2 Dec 2008
Article Copyright 2008 by John Doherty
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid