Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

String.Format equivalent for ASP

, 2 Dec 2008
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 PinmemberDonsw13-Dec-08 7:08 
GeneralOther Methodologies to apply are always welcome... PinmemberTweellt10-Dec-08 4:27 
GeneralThanks for the snippet Pinmemberstylesie8-Dec-08 15:24 
GeneralRe: Thanks for the snippet Pinmemberbjahelka18-Dec-08 14:12 
GeneralIt takes moments to do something that would normally take hours in .Net, plus it always feels so much faster to execute =) Pinmemberbrianma8-Dec-08 12:50 
GeneralRe: It takes moments to do something that would normally take hours in .Net, plus it always feels so much faster to execute =) Pinmemberstylesie8-Dec-08 15:17 
GeneralThat can be done in just one line using RegEx PinmemberFederico Colombo5-Dec-08 14:02 
GeneralRe: That can be done in just one line using RegEx PinmemberAndrewR738-Dec-08 6:25 
GeneralSimilar to my printf Article PinsitebuilderUwe Keim2-Dec-08 10:18 
GeneralRe: Similar to my printf Article PinmemberJohn Doherty2-Dec-08 10:30 
GeneralRe: Similar to my printf Article PinmemberJohn Doherty2-Dec-08 10:36 
GeneralMy vote of 2 Pinmemberrickoshay2-Dec-08 8:54 
GeneralRe: My vote of 2 PinmemberGevorg3-Dec-08 4: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 | Mobile
Web02 | 2.8.140916.1 | Last Updated 2 Dec 2008
Article Copyright 2008 by John Doherty
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid