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

String.Format equivalent for ASP

By John Doherty | 2 Dec 2008
VBScript/ASP version of C# String.format("this {0} a {1}","is","test").
1 vote, 10.0%
1
1 vote, 10.0%
2
2 votes, 20.0%
3
1 vote, 10.0%
4
5 votes, 50.0%
5
4.00/5 - 10 votes
μ 4.00, σa 2.58 [?]

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 PinmemberDonsw8:08 13 Dec '08  
GeneralOther Methodologies to apply are always welcome... PinmemberTweellt5:27 10 Dec '08  
GeneralThanks for the snippet Pinmemberstylesie16:24 8 Dec '08  
GeneralRe: Thanks for the snippet Pinmemberbjahelka15: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 =) Pinmemberbrianma13: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 =) Pinmemberstylesie16:17 8 Dec '08  
GeneralThat can be done in just one line using RegEx PinmemberFederico Colombo15:02 5 Dec '08  
GeneralRe: That can be done in just one line using RegEx PinmemberAndrewR737:25 8 Dec '08  
GeneralSimilar to my printf Article PinsitebuilderUwe Keim11:18 2 Dec '08  
GeneralRe: Similar to my printf Article PinmemberJohn Doherty11:30 2 Dec '08  
GeneralRe: Similar to my printf Article PinmemberJohn Doherty11:36 2 Dec '08  
GeneralMy vote of 2 Pinmemberrickoshay9:54 2 Dec '08  
GeneralRe: My vote of 2 PinmemberGevorg5: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
Web01 | 2.5.120210.1 | Last Updated 2 Dec 2008
Article Copyright 2008 by John Doherty
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid