Lost Password?

  #1 (permalink)  
Old 06-28-2006, 11:27 AM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Credits: 0
Rep Power: 12
NeedHelp is on a distinguished road
Default Tutorial: C# Regex

I figured I would write this little tutorial about C# and Regex since it is still fresh in my mind.

The code below shows how to remove all spaces from a string:

Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace regexconsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a string and display it to the console
            string display = "I have     several   spaces in me";
            Console.WriteLine(display);

            // Replaces all spaces with 1 space
            display = System.Text.RegularExpressions.Regex.Replace(display," +", " ");
            Console.WriteLine(display);

            // Make it pause
            Console.ReadLine();

        }
    }
}

Here is how to determine if a string is a number or not
Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace regexconsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create an integer and display it
            string number = "64";
            Console.WriteLine(number);

            // Determine if it is a positive number
            if (System.Text.RegularExpressions.Regex.IsMatch(number, ("[0-9]*")))
            {
                Console.WriteLine("This is a number");
            }
            else
            {
                Console.WriteLine("This is not a number!");
            }



            // Make it pause
            Console.ReadLine();

        }
    }
}

That is it for now. I will post more later.
__________________
I Need Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-01-2007, 06:25 AM
bassio bassio is offline
Newbie
 
Join Date: May 2007
Posts: 2
Credits: 0
Rep Power: 0
bassio is on a distinguished road
Default

thanks alot man, really nice.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-01-2007, 06:44 AM
v0id's Avatar   
v0id v0id is offline
Super Moderator
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,578
Last Blog:
CherryPy(thon)
Credits: 55
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

It would be nice if you could tell something about regular expressions, and how they works, for those people there doesn't know what it actually is.
I wouldn't call this a tutorial, it had been better with, "Examples" or something.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: C# Hello World Jordan CSharp Tutorials 13 06-26-2008 08:57 AM
John's Java Tutorial Index John Java Tutorials 0 01-11-2007 03:05 PM
regex (yuck) John PHP Forum 9 08-09-2006 12:35 AM
JSP Tutorial encoder JavaScript and CSS 0 05-26-2006 05:31 AM


All times are GMT -5. The time now is 08:50 PM.

Contest Stats

Xav ........ 1357.94
MeTh0Dz|Reb0rn ........ 1075.89
WingedPanther ........ 919.18
marwex89 ........ 906.86
morefood2001 ........ 900.18
John ........ 890.77
Brandon W ........ 770.65
chili5 ........ 312.39
Steve.L ........ 264.99
dcs ........ 232.34

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 83%

Ads