using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LINQTesting
{
    class Program
    {
        static void Main(string[] args)
        {
            const char UnwantedChar = '.';

            string Date = "12.11.1976";
            var DateWithout = new char[8];

            Console.WriteLine("Original date = {0}",Date);
            
            // Get some help from LINQ
            IEnumerable<Char> WithoutTheChar = Date.Where(ch => !ch.Equals(UnwantedChar));

            int CharCount = 0;
            foreach (char ch in WithoutTheChar) //enumerate
            {
                DateWithout[CharCount] = ch;
                CharCount++;
            }

            string NewDate = new String(DateWithout);
            Console.WriteLine("Date cleaned up = {0}", NewDate);
           
            Console.ReadKey();
        }
    }
}
2
Contributors
3
Replies
9
Views
5 Years
Discussion Span
Last Post by ddanbe
0

Think this is an improved version:

namespace LINQTesting
{
    class Program
    {
        static void Main(string[] args)
        {
            const char UnwantedChar = '.';

            string Date = "12.11.1976";

            Console.WriteLine("Original date = {0}",Date);
            
            // Get some help from LINQ
            char[] WithoutTheChar = Date.Where(ch => !ch.Equals(UnwantedChar)).ToArray();
            // convert array of char to string
            string NewDate = new String(WithoutTheChar);
           
            Console.WriteLine("Date cleaned up = {0}", NewDate);
           
            Console.ReadKey();
        }
    }
}
0

@deceptikon: yes you are right!
But I titled this snippet A way, not THE way
I think your suggestion is perhaps the preferred way.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.