How to check if a character in a string is numeric with C#

2 Answers

0 votes
using System;
 
public class Program
{
    public static void Main(string[] args)
    {
        string str = "c# 890";
 
        char character = str[4];
 
        if (char.IsDigit(character)) {
            Console.WriteLine("character is numeric");
        }
    }
}
 
 
 
/*
run:
 
character is numeric
 
*/

 



answered Jun 6, 2024 by avibootz
0 votes
using System;

public class Program
{
	public static void Main(string[] args)
	{
		string str = "c# 890";
		int index = 4;

		if (char.IsDigit(str[index])) {
			Console.WriteLine("character is numeric");
		}
	}
}




/*
run:

character is numeric

*/

 



answered Jun 6, 2024 by avibootz

Related questions

3 answers 186 views
186 views asked Mar 28, 2023 by avibootz
2 answers 152 views
2 answers 169 views
3 answers 221 views
3 answers 203 views
3 answers 321 views
1 answer 157 views
157 views asked Aug 17, 2019 by avibootz
...