Replace() In .NET
ASPAlliance.com: The #1 ASP.NET Community
The ASPSmith
Search
D: | Domains | Authors.aspalliance.com | Stevesmith | Articles | Replace() In .NET
Replace() In .NET

By Steven Smith

[Example/VB]
[Example/C#]

Sometimes it's the little things. Since I just spent about an hour trying to track down how to do a simple Replace() in .NET (you'd think it would be a String class method, wouldn't you?), I figure it's worth a (short) article on the topic. Hopefully this will keep a few of you from wasting time trying to find where Microsoft has hidden the more common VBScript functions, like Replace.

Just to make this article interesting, I'll list the code in all three standard languages of .NET: VB, C#, and JScript. I may even add a working example at some point.

   <%@ Import Namespace="System.IO" %>
   <%@ Import Namespace="System.Text.RegularExpressions" %>
   <script language="VB" runat="server">
   Sub Page_Load(Src As Object, E As EventArgs)
    Dim strTest As String
    strTest = "A sentence with stuff to replace."
    no_replace.text = strTest
    strTest = Regex.Replace(strTest, "to replace", "replaced")
    replace.text = strTest
10   End Sub
11   </script>
12   <html>
13   <body>
14   Original Text: <asp:label id="no_replace" runat="server"/>
15   <hr />
16   Replaced Text: <asp:label id="replace" runat="server"/>
17   </body>
18   </html>
C# VB JScript




ASP.NET Developer's Cookbook, By Steven Smith, Rob Howard, ASPAlliance.com 

ASP.NET By Example, By Steven Smith 




Steven Smith, MCSE + Internet (4.0)
Last Modified: 6/12/2009 10:58:21 AM
History: 6/12/2009 10:58:21 AM