Total Pageviews

Wednesday 11 February 2015

Count symbols,digits ,letters of email id and reverse a String c#

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

namespace test_string
{
    class Program
    {
        public string  reverse_str(string s)
        {
            char[] arr = s.ToCharArray();
            Array.Reverse(arr );
            return new string(arr);
        }


        public void count_str()
        {
           string text = "akash02sap@gmail.com";
            int result = text.Count(c=> Char.IsDigit (c ));
            Console.WriteLine("No of digits in a mail:{0}",result );

            int result2 = text.Count(c => Char.IsLetter (c));
            Console.WriteLine("No of letters in a mail:{0}", result2);

            int result3 = text.Count(c => !Char.IsLetterOrDigit(c));
            Console.WriteLine("No of symbols in a mail:{0}", result3);
       }


        static void Main(string[] args)
        {

         
            Program p = new Program();
            Console.WriteLine("Reverse of string :{0}",p.reverse_str("akash"));
            p.count_str();
        }
    }
}