Stripping non-numeric characters from a string in C#

Posted: May 13th, 2011 | Author: | Tags: , , , | No Comments »

 

string output = Regex.Replace("String 2 Parse 4 Non Numerics", "[^0-9]", string.Empty)

In this case the variable “output” will hold the value “24″


.Net MVC Html Helper Example

Posted: May 8th, 2010 | Author: | Tags: , , , | No Comments »
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;
using System.Web.Mvc;
 
namespace MvcApplication1.Helpers
{
     public static class HtmlHelperExtensions // needs to be a static class
     {
          public static string MyHelper(this HtmlHelper helper, string arg1, string arg2)
          {
                string output = string.Empty();
               // do stuff
               return output; // return a string
          }
     }
}

And don’t forget import the Namespace in your view!

1
<%@ Import Namespace="MvcApplication1.Helpers" %>