Posts

Showing posts from August, 2009

Dot NET Regular Expression

Hi, in this post, I will demonstrate how to use a Regular Expression using the Dot NET Framework. If you are new to Regular Expressions, this post would not be of much use. This is intended for an audience who knows regular expressions and need to implement a regular expression in their Dot NET code. There may be scenarios where you need to match a certain string with a Regular Expression. Using the Dot NET Framework, this becomes relatively easy. First, you need to import the namespace by defining using System.Text.RegularExpressions; Then, you can create a Regex object by calling its constructor. This is an overloaded constructor. I will show only one use of it. (You can explore the other!!!) Regex regularExpression = new Regex(" "); This would create a Regex object. Once created, you can call several methods to get the job done. I will show how the Replace method can be used to identify a character pattern and replace it with a character set of your own. (A good example i

Dot Net Date Formatting

Hi, all of you people may have encountered situation where you wish to format your date for a specific format. This becomes very simple with Dot NET Framework. Suppose you have a date to be displayed. Let the date be 1st January 2009 Now, this can be displayed in various formats. The respective date-format-string is displayed alongside Eg: Displaying these can be done using the following LOC. DateTime today=DateTime.Now; string formattedDate=today.ToString( ); Eg: string formattedDate=today.ToString("dd-MM-yyyy"); =>01-Jan-2009 string formattedDate=today.ToString("dd/MM/yyyy"); =>01-Jan/2009 string formattedDate=today.ToString("d-MMM-yy"); =>1-January-2009 Try out other combinations of your own and experience the power!!!!!!! Format Respective date-format-string 01/01/09 'dd/MM/yy' 01 Jan 09 'dd MM yy' 01 Jan 2009 'dd MM yyyy' 1 January 2009 'd MMM yyyy'