Click here to Skip to main content
Licence CPOL
First Posted 2 Dec 2008
Views 19,539
Bookmarked 15 times

String.Format equivalent for ASP

By | 2 Dec 2008 | Article
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)

About the Author

John Doherty

Chief Technology Officer
MammothWorkwear.com
United Kingdom United Kingdom

Member

Senior Web Developer/Systems Architect, One of the developers behind the 1999-2003 web based groupware application DeskVu/Convea. Presently CTO of MammothWorkwear.com, the UK's largest supplier of Dickies Workwear, Snickers Workwear and Caterpillar Workwear.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGood insight PinmemberDonsw7:08 13 Dec '08  
Have you tried this for several doifferent data types? Smile | :)
GeneralOther Methodologies to apply are always welcome... PinmemberTweellt4:27 10 Dec '08  
GeneralThanks for the snippet Pinmemberstylesie15:24 8 Dec '08  
GeneralRe: Thanks for the snippet Pinmemberbjahelka14:12 18 Dec '08  
GeneralIt takes moments to do something that would normally take hours in .Net, plus it always feels so much faster to execute =) Pinmemberbrianma12:50 8 Dec '08  
GeneralRe: It takes moments to do something that would normally take hours in .Net, plus it always feels so much faster to execute =) Pinmemberstylesie15:17 8 Dec '08  
GeneralThat can be done in just one line using RegEx PinmemberFederico Colombo14:02 5 Dec '08  
GeneralRe: That can be done in just one line using RegEx PinmemberAndrewR736:25 8 Dec '08  
GeneralSimilar to my printf Article PinsitebuilderUwe Keim10:18 2 Dec '08  
GeneralRe: Similar to my printf Article PinmemberJohn Doherty10:30 2 Dec '08  
GeneralRe: Similar to my printf Article PinmemberJohn Doherty10:36 2 Dec '08  
GeneralMy vote of 2 Pinmemberrickoshay8:54 2 Dec '08  
GeneralRe: My vote of 2 PinmemberGevorg4:59 3 Dec '08  

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.

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