How to determine if a character is a letter or digit in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "c# 1 c++ 2 java ! python ?";
            Console.WriteLine(s);

            foreach (char ch in s)
            {
                if (char.IsLetterOrDigit(ch))
                {
                    Console.Write('y');
                }
                else
                {
                    Console.Write(' ');
                }
            }
        }
    }
}


/*
run:

c# 1 c++ 2 java ! python ?
y  y y   y yyyy   yyyyyy  

*/

 



answered Mar 8, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            char ch = 'w';

            bool b;

            b = char.IsLetterOrDigit(ch);
            Console.WriteLine(b);
            b = char.IsLetterOrDigit('7');
            Console.WriteLine(b);
            b = char.IsLetterOrDigit('\n');
            Console.WriteLine(b);
        }
    }
}


/*
run:

True
True
False

*/

 



answered Mar 8, 2017 by avibootz

Related questions

2 answers 188 views
1 answer 195 views
2 answers 106 views
1 answer 110 views
1 answer 186 views
1 answer 179 views
...