<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Collection of VBScript string functions for classic ASP</title>
	<atom:link href="http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/</link>
	<description>hot talk about web development</description>
	<lastBuildDate>Tue, 10 May 2011 13:11:20 +0200</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: English Classics</title>
		<link>http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-9607</link>
		<dc:creator>English Classics</dc:creator>
		<pubDate>Tue, 23 Dec 2008 03:31:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-9607</guid>
		<description>Very neat, indeed.  Both of my websites are in classic ASP so some of these may definitely come in handy.</description>
		<content:encoded><![CDATA[<p>Very neat, indeed.  Both of my websites are in classic ASP so some of these may definitely come in handy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michal</title>
		<link>http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8823</link>
		<dc:creator>Michal</dc:creator>
		<pubDate>Fri, 11 Jul 2008 15:54:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8823</guid>
		<description>thanks craig for your samples and your ideas ... this made me playing around today for some time :) 
yeah the regex object creation takes the most time .. but i discovered that the main problem with your approach is that its execution lasts longer when the placeholders are used more than once in a string. example:

[asp]
format(&quot;{0}{1}{0}{0}&quot;, array(1, 2))
[/asp]

first i have tried the approach i mentioned to you .. which resulted in this:

[asp]
public function format3(byVal str, byVal args)
	if not isArray(args) then args = array(args)
	set rx = new RegExp
	for i = 0 to uBound(args)
		rx.pattern = &quot;([^_]&#124;^)\{&quot; &amp; i &amp; &quot;\}([^_]&#124;$)&quot;
		rx.global = true
		str = rx.replace(str, &quot;$1_&quot; &amp; args(i) &amp; &quot;_$2&quot;)
	next
	format3 = replace(str, &quot;_&quot;, &quot;&quot;)
end function
[/asp]

problem was that it looks shorter but takes even longer :))) however this approach led me to my final solution which seems the best i guess.. its also almost the same speed as the original one. 

[asp]
function format(byVal str, byVal values)
	escapeChar = asc(24) &amp; asc(27)
	if instr(str, escapeChar) &gt; 0 then
		response.write(&quot;unsupported char found in input string&quot;)
		response.end()
	end if
	if not isArray(values) then values = array(values)
	for i = 0 to ubound(values)
		val = cStr(values(i))
		if instr(val, escapeChar) &gt; 0 then
			response.write(&quot;unsupported char found in argument&quot;)
			response.end()
		end if
		val = replace(val, &quot;{&quot;, escapeChar)
		str = replace(str, &quot;{&quot; &amp; i &amp; &quot;}&quot;, val)
	next
	format = replace(str, escapeChar, &quot;{&quot;)
end function
[/asp]

the only little odd on this is that in theory the string could contain a sequence of chars which is used internally for escaping. this results in an error then .. but the chance is very very low .. take a look at the code.
Thanks for your inspiration craig and your time! the updated version can be found in the ajaxed SVN as this file here is not maintained.

btw the code i ran for my benchmarks is the following:

[asp]
values = array( _
		&quot;{0}{1}{2}{3}{4}{5}{6}{7}{8}{0}{1}{2}{3}{4}{5}{6}{7}{8}&quot;, _
		&quot;asdasdasda{0}asdasd{1}asdasda{2}asdasda{3}adsad{4}adsad{5}adsad{6}asdad{7}asdad{8}asdasdda&quot;, _
		&quot;{0}{1}{2}{3}asdasd{4}{5}{7}{8}adasda{0}{1}{2}{3}asdasd{4}{5}{7}{8}&quot; _
	)
	s = timer()
	for each v in values
		for i = 0 to 1000
			x = str.format(v, array(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;, &quot;g&quot;, &quot;h&quot;, &quot;j&quot;))
		next
	next
	str.write(&quot;new: &quot; &amp; timer() - s)
[/asp]

last but not least: the new function also supports a non-array as argument as well. This is useful if you only need one argument to replace.</description>
		<content:encoded><![CDATA[<p>thanks craig for your samples and your ideas ... this made me playing around today for some time :)<br />
yeah the regex object creation takes the most time .. but i discovered that the main problem with your approach is that its execution lasts longer when the placeholders are used more than once in a string. example:</p>
<div class="igBar"><span id="lasp-1"><a href="#" onclick="javascript:showCodeTxt('asp-1'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-1">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">format<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"{0}{1}{0}{0}"</span>, <span style="color:#990099; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;color:#800000;">1</span>, <span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>first i have tried the approach i mentioned to you .. which resulted in this:</p>
<div class="igBar"><span id="lasp-2"><a href="#" onclick="javascript:showCodeTxt('asp-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-2">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">public</span> <span style="color:#0000FF; font-weight:bold;">function</span> format3<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#990099; font-weight:bold;">byVal</span> str, <span style="color:#990099; font-weight:bold;">byVal</span> args<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> <span style="color:#990099; font-weight:bold;">not</span> <span style="color:#990099; font-weight:bold;">isArray</span><span style="color:#006600; font-weight:bold;">&#40;</span>args<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#990099; font-weight:bold;">then</span> args = <span style="color:#990099; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#40;</span>args<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">set</span> rx = <span style="color:#0000FF; font-weight:bold;">new</span> <span style="color:#990099; font-weight:bold;">RegExp</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">for</span> i = <span style="color:#800000;color:#800000;">0</span> <span style="color:#990099; font-weight:bold;">to</span> <span style="color:#990099; font-weight:bold;">uBound</span><span style="color:#006600; font-weight:bold;">&#40;</span>args<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; rx.<span style="color:#330066;">pattern</span> = <span style="color:#CC0000;">"([^_]|^)<span style="color:#000099; font-weight:bold;">\{</span>"</span> &amp; i &amp; <span style="color:#CC0000;">"<span style="color:#000099; font-weight:bold;">\}</span>([^_]|$)"</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; rx.<span style="color:#990099; font-weight:bold;">global</span> = <span style="color:#0000FF; font-weight:bold;">true</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; str = rx.<span style="color:#990099; font-weight:bold;">replace</span><span style="color:#006600; font-weight:bold;">&#40;</span>str, <span style="color:#CC0000;">"$1_"</span> &amp; args<span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span> &amp; <span style="color:#CC0000;">"_$2"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">next</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; format3 = <span style="color:#990099; font-weight:bold;">replace</span><span style="color:#006600; font-weight:bold;">&#40;</span>str, <span style="color:#CC0000;">"_"</span>, <span style="color:#CC0000;">""</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">function</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>problem was that it looks shorter but takes even longer :))) however this approach led me to my final solution which seems the best i guess.. its also almost the same speed as the original one. </p>
<div class="igBar"><span id="lasp-3"><a href="#" onclick="javascript:showCodeTxt('asp-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-3">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF; font-weight:bold;">function</span> format<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#990099; font-weight:bold;">byVal</span> str, <span style="color:#990099; font-weight:bold;">byVal</span> values<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; escapeChar = asc<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;color:#800000;">24</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp; asc<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;color:#800000;">27</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> <span style="color:#990099; font-weight:bold;">instr</span><span style="color:#006600; font-weight:bold;">&#40;</span>str, escapeChar<span style="color:#006600; font-weight:bold;">&#41;</span>&gt; <span style="color:#800000;color:#800000;">0</span> <span style="color:#990099; font-weight:bold;">then</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">response</span>.<span style="color:#330066;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"unsupported char found in input string"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">response</span>.<span style="color:#990099; font-weight:bold;">end</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#990099; font-weight:bold;">if</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> <span style="color:#990099; font-weight:bold;">not</span> <span style="color:#990099; font-weight:bold;">isArray</span><span style="color:#006600; font-weight:bold;">&#40;</span>values<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#990099; font-weight:bold;">then</span> values = <span style="color:#990099; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#40;</span>values<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">for</span> i = <span style="color:#800000;color:#800000;">0</span> <span style="color:#990099; font-weight:bold;">to</span> <span style="color:#990099; font-weight:bold;">ubound</span><span style="color:#006600; font-weight:bold;">&#40;</span>values<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; val = <span style="color:#990099; font-weight:bold;">cStr</span><span style="color:#006600; font-weight:bold;">&#40;</span>values<span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">if</span> <span style="color:#990099; font-weight:bold;">instr</span><span style="color:#006600; font-weight:bold;">&#40;</span>val, escapeChar<span style="color:#006600; font-weight:bold;">&#41;</span>&gt; <span style="color:#800000;color:#800000;">0</span> <span style="color:#990099; font-weight:bold;">then</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">response</span>.<span style="color:#330066;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"unsupported char found in argument"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">response</span>.<span style="color:#990099; font-weight:bold;">end</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">end</span> <span style="color:#990099; font-weight:bold;">if</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; val = <span style="color:#990099; font-weight:bold;">replace</span><span style="color:#006600; font-weight:bold;">&#40;</span>val, <span style="color:#CC0000;">"{"</span>, escapeChar<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; str = <span style="color:#990099; font-weight:bold;">replace</span><span style="color:#006600; font-weight:bold;">&#40;</span>str, <span style="color:#CC0000;">"{"</span> &amp; i &amp; <span style="color:#CC0000;">"}"</span>, val<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">next</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; format = <span style="color:#990099; font-weight:bold;">replace</span><span style="color:#006600; font-weight:bold;">&#40;</span>str, escapeChar, <span style="color:#CC0000;">"{"</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">function</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>the only little odd on this is that in theory the string could contain a sequence of chars which is used internally for escaping. this results in an error then .. but the chance is very very low .. take a look at the code.<br />
Thanks for your inspiration craig and your time! the updated version can be found in the ajaxed SVN as this file here is not maintained.</p>
<p>btw the code i ran for my benchmarks is the following:</p>
<div class="igBar"><span id="lasp-4"><a href="#" onclick="javascript:showCodeTxt('asp-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-4">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">values = <span style="color:#990099; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#40;</span> _</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0000;">"{0}{1}{2}{3}{4}{5}{6}{7}{8}{0}{1}{2}{3}{4}{5}{6}{7}{8}"</span>, _</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0000;">"asdasdasda{0}asdasd{1}asdasda{2}asdasda{3}adsad{4}adsad{5}adsad{6}asdad{7}asdad{8}asdasdda"</span>, _</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0000;">"{0}{1}{2}{3}asdasd{4}{5}{7}{8}adasda{0}{1}{2}{3}asdasd{4}{5}{7}{8}"</span> _</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; s = timer<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">for</span> <span style="color:#990099; font-weight:bold;">each</span> v <span style="color:#990099; font-weight:bold;">in</span> values</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">for</span> i = <span style="color:#800000;color:#800000;">0</span> <span style="color:#990099; font-weight:bold;">to</span> <span style="color:#800000;color:#800000;">1000</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x = str.<span style="color:#9900CC;">format</span><span style="color:#006600; font-weight:bold;">&#40;</span>v, <span style="color:#990099; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"a"</span>, <span style="color:#CC0000;">"b"</span>, <span style="color:#CC0000;">"c"</span>, <span style="color:#CC0000;">"d"</span>, <span style="color:#CC0000;">"e"</span>, <span style="color:#CC0000;">"f"</span>, <span style="color:#CC0000;">"g"</span>, <span style="color:#CC0000;">"h"</span>, <span style="color:#CC0000;">"j"</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">next</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">next</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; str.<span style="color:#330066;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"new: "</span> &amp; timer<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> - s<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>last but not least: the new function also supports a non-array as argument as well. This is useful if you only need one argument to replace.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8803</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Thu, 10 Jul 2008 22:45:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8803</guid>
		<description>Eh, forget about the previous data (lies, damn lies, and statistics). I had a bug in the performance code where the test string was modified making the tests run faster. Here is the new code: http://pastebin.com/m3a71221e

In hindsite, the tests only showed that the methods both perform linearly on the same length of args array and same number of replacements. I&#039;ve varied the number of the replacements in the new code.

I found that both methods performed linearly based on the number of replacements made. The average time (on my development box) per a replacement was 0.0015 ms for the original method and 0.0362 ms for the new method. Since this it was O(n) and the difference is a fraction of a millisecond, I&#039;ve decided to run with it for our code base ;)</description>
		<content:encoded><![CDATA[<p>Eh, forget about the previous data (lies, damn lies, and statistics). I had a bug in the performance code where the test string was modified making the tests run faster. Here is the new code: <a href="http://pastebin.com/m3a71221e" rel="nofollow">http://pastebin.com/m3a71221e</a></p>
<p>In hindsite, the tests only showed that the methods both perform linearly on the same length of args array and same number of replacements. I've varied the number of the replacements in the new code.</p>
<p>I found that both methods performed linearly based on the number of replacements made. The average time (on my development box) per a replacement was 0.0015 ms for the original method and 0.0362 ms for the new method. Since this it was O(n) and the difference is a fraction of a millisecond, I've decided to run with it for our code base ;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8792</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Thu, 10 Jul 2008 16:27:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8792</guid>
		<description>Ok, but it&#039;s premature optimization without data, so here is some:
http://pastebin.com/m34fb4206
It&#039;s a csv, so you can download and import into Excel/Calc/whatever.

I already identified the most expensive operation, creating the RegExp object. After moving the RegExp out of the method scope and into a global, the new method actually performs better in most cases, and the same in one case.

Here&#039;s the performance code: http://pastebin.com/m6fb6609d

Both of the pastebins will last a month.

I&#039;m not sure if I understand the special character wrapping solution. Perhaps an example would help?</description>
		<content:encoded><![CDATA[<p>Ok, but it's premature optimization without data, so here is some:<br />
<a href="http://pastebin.com/m34fb4206" rel="nofollow">http://pastebin.com/m34fb4206</a><br />
It's a csv, so you can download and import into Excel/Calc/whatever.</p>
<p>I already identified the most expensive operation, creating the RegExp object. After moving the RegExp out of the method scope and into a global, the new method actually performs better in most cases, and the same in one case.</p>
<p>Here's the performance code: <a href="http://pastebin.com/m6fb6609d" rel="nofollow">http://pastebin.com/m6fb6609d</a></p>
<p>Both of the pastebins will last a month.</p>
<p>I'm not sure if I understand the special character wrapping solution. Perhaps an example would help?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michal</title>
		<link>http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8790</link>
		<dc:creator>Michal</dc:creator>
		<pubDate>Thu, 10 Jul 2008 15:02:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8790</guid>
		<description>thx craig ... i am just a bit concerned about performance because this function is used very often in a lot of apps and the change compared to the previous one is dramatic.
i am just doing some brainstorming if there would be maybe other solutions as well .. you know some function like this is called a lot.

i was thinking of something like:
1. looping through all given placeholders
2. replacing its occurencies and surrounding it with some special char. the special char would prevent the repeated replacement (if regex is done correctly)
3. remove all the special chars.

havent tried yet if it would work .. what do you think? if yes, what char could we use?</description>
		<content:encoded><![CDATA[<p>thx craig ... i am just a bit concerned about performance because this function is used very often in a lot of apps and the change compared to the previous one is dramatic.<br />
i am just doing some brainstorming if there would be maybe other solutions as well .. you know some function like this is called a lot.</p>
<p>i was thinking of something like:<br />
1. looping through all given placeholders<br />
2. replacing its occurencies and surrounding it with some special char. the special char would prevent the repeated replacement (if regex is done correctly)<br />
3. remove all the special chars.</p>
<p>havent tried yet if it would work .. what do you think? if yes, what char could we use?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8786</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Thu, 10 Jul 2008 13:15:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8786</guid>
		<description>It&#039;s not pretty, but I&#039;ve come to terms with ASP code never looking pretty ;). I concat Left(...) with the Replace return because the Replace function truncates the string to the left of start.

[asp]
public function StringFormat(str, args())
   if not IsArray(args) then
      StringFormat = str
      exit function
   end if

   if ubound(args) = -1 then
      StringFormat = str
      exit function
   end if
   
   dim regex : set regex = new RegExp
   regex.Pattern = &quot;{\d+}&quot;
   regex.Global = true

   dim match, i, shift
   shift = 1

   for each match in regex.Execute(str)
      i = CInt(Mid(match.Value, 2, Len(match.Value) - 2))
      str = Left(str, match.FirstIndex + shift - 1) &amp; Replace(str, match.Value, args(i), match.FirstIndex + shift, 1, 0)
      shift = shift + Len(args(i)) - Len(match.Value)
   next
   StringFormat = str
end function
[/asp]</description>
		<content:encoded><![CDATA[<p>It's not pretty, but I've come to terms with ASP code never looking pretty ;). I concat Left(...) with the Replace return because the Replace function truncates the string to the left of start.</p>
<div class="igBar"><span id="lasp-5"><a href="#" onclick="javascript:showCodeTxt('asp-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ASP:</span>
<div id="asp-5">
<div class="asp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">public</span> <span style="color:#0000FF; font-weight:bold;">function</span> StringFormat<span style="color:#006600; font-weight:bold;">&#40;</span>str, args<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#990099; font-weight:bold;">if</span> <span style="color:#990099; font-weight:bold;">not</span> <span style="color:#990099; font-weight:bold;">IsArray</span><span style="color:#006600; font-weight:bold;">&#40;</span>args<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#990099; font-weight:bold;">then</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; StringFormat = str</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">exit</span> <span style="color:#0000FF; font-weight:bold;">function</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#990099; font-weight:bold;">end</span> <span style="color:#990099; font-weight:bold;">if</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#990099; font-weight:bold;">if</span> <span style="color:#990099; font-weight:bold;">ubound</span><span style="color:#006600; font-weight:bold;">&#40;</span>args<span style="color:#006600; font-weight:bold;">&#41;</span> = -<span style="color:#800000;color:#800000;">1</span> <span style="color:#990099; font-weight:bold;">then</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; StringFormat = str</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#990099; font-weight:bold;">exit</span> <span style="color:#0000FF; font-weight:bold;">function</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#990099; font-weight:bold;">end</span> <span style="color:#990099; font-weight:bold;">if</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#0000FF; font-weight:bold;">dim</span> regex : <span style="color:#990099; font-weight:bold;">set</span> regex = <span style="color:#0000FF; font-weight:bold;">new</span> <span style="color:#990099; font-weight:bold;">RegExp</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;regex.<span style="color:#330066;">Pattern</span> = <span style="color:#CC0000;">"{<span style="color:#000099; font-weight:bold;">\d</span>+}"</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;regex.<span style="color:#990099; font-weight:bold;">Global</span> = <span style="color:#0000FF; font-weight:bold;">true</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#0000FF; font-weight:bold;">dim</span> match, i, shift</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;shift = <span style="color:#800000;color:#800000;">1</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#990099; font-weight:bold;">for</span> <span style="color:#990099; font-weight:bold;">each</span> match <span style="color:#990099; font-weight:bold;">in</span> regex.<span style="color:#330066;">Execute</span><span style="color:#006600; font-weight:bold;">&#40;</span>str<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; i = <span style="color:#990099; font-weight:bold;">CInt</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#990099; font-weight:bold;">Mid</span><span style="color:#006600; font-weight:bold;">&#40;</span>match.<span style="color:#330066;">Value</span>, <span style="color:#800000;color:#800000;">2</span>, <span style="color:#990099; font-weight:bold;">Len</span><span style="color:#006600; font-weight:bold;">&#40;</span>match.<span style="color:#330066;">Value</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; str = <span style="color:#990099; font-weight:bold;">Left</span><span style="color:#006600; font-weight:bold;">&#40;</span>str, match.<span style="color:#330066;">FirstIndex</span> + shift - <span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;amp; <span style="color:#990099; font-weight:bold;">Replace</span><span style="color:#006600; font-weight:bold;">&#40;</span>str, match.<span style="color:#330066;">Value</span>, args<span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span>, match.<span style="color:#330066;">FirstIndex</span> + shift, <span style="color:#800000;color:#800000;">1</span>, <span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; shift = shift + <span style="color:#990099; font-weight:bold;">Len</span><span style="color:#006600; font-weight:bold;">&#40;</span>args<span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#990099; font-weight:bold;">Len</span><span style="color:#006600; font-weight:bold;">&#40;</span>match.<span style="color:#330066;">Value</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#990099; font-weight:bold;">next</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;StringFormat = str</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#990099; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">function</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michal</title>
		<link>http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8785</link>
		<dc:creator>Michal</dc:creator>
		<pubDate>Wed, 09 Jul 2008 07:58:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8785</guid>
		<description>craig thats right .. thx for pointing this out... do u have an idea how to solve this nicely? thx for any comments</description>
		<content:encoded><![CDATA[<p>craig thats right .. thx for pointing this out... do u have an idea how to solve this nicely? thx for any comments</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8783</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Tue, 08 Jul 2008 17:14:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-8783</guid>
		<description>Your Format method does not support the following: Format(&quot;{0}{1}&quot;, array(&quot;{1}&quot;, &quot;{0}&quot;)). Output should be &quot;{1}{0}&quot; but will be &quot;{0}{0}&quot;.</description>
		<content:encoded><![CDATA[<p>Your Format method does not support the following: Format("{0}{1}", array("{1}", "{0}")). Output should be "{1}{0}" but will be "{0}{0}".</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CC</title>
		<link>http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-2383</link>
		<dc:creator>CC</dc:creator>
		<pubDate>Sat, 02 Feb 2008 12:06:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-2383</guid>
		<description>glitch in stringOperations.asp
public function JSEncode(byVal val)
val = val &amp; “”
tmp = replace(val, chr(39), “\’”) &#039;it should be here
tmp = replace(tmp, chr(92), “\\”)
‘tmp = replace(val, chr(39), “\’”) the order is not correct
tmp = replace(tmp, chr(34), “&quot;”)
tmp = replace(tmp, chr(13), “”)
tmp = replace(tmp, chr(10), ” “)
JSEncode = tmp
end function


better follow the XHTML way to use “hidden” instead of “Hidden” in
public function getHiddenInput(name, value)</description>
		<content:encoded><![CDATA[<p>glitch in stringOperations.asp<br />
public function JSEncode(byVal val)<br />
val = val &amp; “”<br />
tmp = replace(val, chr(39), “\’”) 'it should be here<br />
tmp = replace(tmp, chr(92), “\\”)<br />
‘tmp = replace(val, chr(39), “\’”) the order is not correct<br />
tmp = replace(tmp, chr(34), “"”)<br />
tmp = replace(tmp, chr(13), “”)<br />
tmp = replace(tmp, chr(10), ” “)<br />
JSEncode = tmp<br />
end function</p>
<p>better follow the XHTML way to use “hidden” instead of “Hidden” in<br />
public function getHiddenInput(name, value)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: retro</title>
		<link>http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-1137</link>
		<dc:creator>retro</dc:creator>
		<pubDate>Thu, 01 Nov 2007 14:51:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2006/11/20/collection-of-vbscript-string-functions-for-classic-asp/#comment-1137</guid>
		<description>I do love the classics.</description>
		<content:encoded><![CDATA[<p>I do love the classics.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

