Tech Point Fundamentals

Tuesday, December 21, 2021

C# Program to Find the Numeric Characters Count in a String

C# Program to Find the Numeric Characters Count in a String

coding-interview-question-csharp

Most of the IT companies check the coding skills and problem-solving skills as well along with the theoretical interview questions. Sometimes you are free to write the pseudo code and sometimes you are asked to write the complete program either on any paper or any editor. 


This question is asked in the coding interview to write the program. Here you can find the program as well as a live running program so that you can test the program immediately.


Watch our videos here





Question: 


How can you find the total number of numeric characters in a string? Write a program to find the numeric characters in a string.




C# Program To Find the Numeric Characters Count in a String


       
 

// Author 	: Tech Point Fundamentals
// Website 	: www.techpointfunda.com
// Channel	: https://www.youtube.com/c/TechPointFundamentals
// Demo		: Finding Numeric Character in String

using System;

public class Program
{
public static void Main()
{
  string inputString = "Tech 123 Point 498 Fundamentals 0";		
  
  Console.WriteLine("Input String : " + inputString);		
  Console.WriteLine("Numeric Characters Count : " + NumericCharactersCount(inputString));			
}	  	
	
public static int NumericCharactersCount(string inputString)    
{		
  int count = 0;      
  
  for (int i = 0; i < inputString.Length; i++)
  {
  	if ((inputString[i] >= '0') && (inputString[i] <= '9'))
  	{
  		count++;
  	}
  }
  return count;
}	
}





Output: 

Input String : Tech 123 Point 498 Fundamentals 0
Numeric Characters Count : 7



Live Demo






No comments:

Post a Comment

Please do not enter any HTML. JavaScript or spam link in the comment box.