|
||||||
| CSharp Tutorials Tutorials for C# |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
| Sponsored Links |
|
|
|
|||||
|
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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum C/C++ resources - C/C++ frequently asked questions Python resources - Python frequently asked questions I'm always up for a chat, so feel free to contact me... |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |
| 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 |
Goal: 100,000 Posts
Complete: 83%