The code below shows how to remove all spaces from a string:
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
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.


Sign In
Create Account

Guest_NeedHelp_*
Back to top












