Click here to Skip to main content
5,786,882 members and growing! (20,392 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
Updated: 2 Dec 2008
Views: 2,402
Bookmarked: 8 times
Note: This is an unedited reader contribution
Announcements
Loading...



Search    
Advanced Search
Sitemap
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
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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


A highly experienced 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

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 13 of 13 (Total in Forum: 13) (Refresh)FirstPrevNext
GeneralGood insightmemberDonsw8:08 13 Dec '08  
GeneralOther Methodologies to apply are always welcome...memberTweellt5:27 10 Dec '08  
GeneralThanks for the snippetmemberstylesie16:24 8 Dec '08  
GeneralRe: Thanks for the snippetmemberbjahelka15: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 =)memberbrianma13: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 =)memberstylesie16:17 8 Dec '08  
GeneralThat can be done in just one line using RegExmemberFederico Colombo15:02 5 Dec '08  
GeneralRe: That can be done in just one line using RegExmemberAndrewR737:25 8 Dec '08  
GeneralSimilar to my printf ArticlesitebuilderUwe Keim11:18 2 Dec '08  
GeneralRe: Similar to my printf ArticlememberJohn Doherty11:30 2 Dec '08  
GeneralRe: Similar to my printf ArticlememberJohn Doherty11:36 2 Dec '08  
GeneralMy vote of 2memberrickoshay9:54 2 Dec '08  
GeneralRe: My vote of 2memberGevorg5: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
Web20 | Advertise on the Code Project