<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/">
  <channel>
    <title>Simulating VB.NET's lost String() function</title>
    <link>http://blogs.lotterypost.com/speednet/2007/10/simulating-vbnets-lost-space-function.htm</link>
    <atom:link href="http://www.lotterypost.com/rss/blogcomments/19257" rel="self" type="application/rss+xml" />
    <description>Speednet's Blog: Simulating VB.NET's lost String() function</description>
    <dc:language>en-us</dc:language>
    <generator>Lottery Post RSS Generator</generator>
    <item>
      <title>Comment #1</title>
      <link>http://blogs.lotterypost.com/speednet/2007/10/simulating-vbnets-lost-space-function.htm</link>
      <guid isPermaLink="true">http://blogs.lotterypost.com/speednet/2007/10/simulating-vbnets-lost-space-function.htm</guid>
      <pubDate>Fri, 12 Oct 2007 21:37:29 GMT</pubDate>
      <dc:creator>JADELottery</dc:creator>
      <description><![CDATA[Interesting... nice to know... I read these blogs from time-to-time... great read.]]></description>
      <category>JADELottery</category>
    </item>
    <item>
      <title>Original Blog Entry: Simulating VB.NET's lost String() function</title>
      <link>http://blogs.lotterypost.com/speednet/2007/10/simulating-vbnets-lost-space-function.htm</link>
      <guid isPermaLink="true">http://blogs.lotterypost.com/speednet/2007/10/simulating-vbnets-lost-space-function.htm</guid>
      <pubDate>Fri, 12 Oct 2007 15:35:56 GMT</pubDate>
      <dc:creator>Speednet</dc:creator>
      <description><![CDATA[<p>Before VB.NET was around &mdash; back in the days it was just called &quot;Visual Basic&quot; &mdash; there was a function named <span style="font-family: courier new,courier">String()</span>, which was used to repeat a character sequence multiple times.</p><p>For example, <span style="font-family: courier new,courier">String(&quot;Abc&quot;, 5)</span> produced <span style="font-family: courier new,courier">&quot;AbcAbcAbcAbcAbc&quot;</span>.</p><p>In VB.NET, the <span style="font-family: courier new,courier">String()</span> function was dropped, probably because the name conflicts with the construction of a new String value, as in <span style="font-family: courier new,courier">Dim str As New String()</span>.</p><p>When they dropped it from the language, I would have thought that they would replace it with a new function &mdash; maybe something like <span style="font-family: courier new,courier">StrClone()</span>.</p><p>Searching the web, the question seems to be asked quite often, &quot;How can you do the equivalent of String() in VB.NET?&quot;</p><p>Annoyingly, every time it is&nbsp;asked, someone invariably answers by saying they should use the <span style="font-family: courier new,courier">StrDup()</span> function, or <span style="font-family: courier new,courier">New String(&quot;A&quot;, 5)</span>.&nbsp; They completely disregard that the person wants to concatenate a multi-character string, not one character.</p><p>One person even suggested incorrectly that the String constructor could be used to do it &mdash; as in <span style="font-family: courier new,courier">New String(&quot;Abc&quot;, 5)</span> &mdash; which it can't.&nbsp; That would produce a string of 5 &quot;A&quot; characters.</p><p>So here is an easy solution.</p><p>To create a string consisting of 10 copies of &quot;Abc&quot;:</p><p><span style="font-family: courier new,courier">MyString = Replace(Space(10), &quot; &quot;, &quot;Abc&quot;)</span></p><p>Or, if you want to use all .NET framework methods (instead of the Visual Basic library), use the following:</p><p><span style="font-family: courier new,courier">MyString = New String(&quot; &quot;c, 10).Replace(&quot; &quot;, &quot;Abc&quot;)</span></p><p>Note: the &quot;c&quot; character after the space (&quot; &quot;c) means a literal character (Char) instead of a character string.&nbsp; It is a tiny efficiency.</p><p>Yes, there are other ways of doing this, perhaps by manipulating character arrays.&nbsp; This, however, is a simple, m....</p><p>[ <a href="http://blogs.lotterypost.com/speednet/2007/10/simulating-vbnets-lost-space-function.htm">More</a> ]</p>]]></description>
      <category>* Original Blog Entry</category>
      <wfw:comment>http://www.lotterypost.com/blogentry/19257</wfw:comment>
    </item>
  </channel>
</rss>
