Click here to Skip to main content
6,630,586 members and growing! (17,006 online)
Email Password   helpLost your password?
Web Development » ASP » General License: The Code Project Open License (CPOL)

String.Format equivalent

By John Doherty

VBScript/ASP version of the C# string.format("this {0} a {1}","is","test")
VBScript, ASP
Posted:2 Dec 2008
Views:7,994
Bookmarked:11 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
10 votes for this article.
Popularity: 4.00 Rating: 4.00 out of 5
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

Introduction

Classic ASP - String.Format equivalent function

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 created my own and thought I would share.

Using 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


Member
Senior web application developer. One of two developers behind the 1999-2003 web based groupware application DeskVu/Convea. Presently Technical Director of www.MammothWorkwear.com, the UK's largest supplier of Dickies, DeWalt and Caterpillar workwear.
Occupation: Chief Technology Officer
Company: MammothWorkwear.com
Location: United Kingdom United Kingdom

Other popular ASP articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 13 of 13 (Total in Forum: 13) (Refresh)FirstPrevNext
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    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 2 Dec 2008
Editor:
Copyright 2008 by John Doherty
Everything else Copyright © CodeProject, 1999-2009
Web09 | Advertise on the Code Project