I have a program see below
I made the method but I want to display it in the console and not on the easy way like console.writeline(str.length). I want using the method I made.
could someone help me please
thanks in advance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string str = "dit is een test 1,2,3";
Console.WriteLine(str);
}
public int CountAllNumbersAndChar(string str)
{
return str.Length;
}
}
}
I have the following program now
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string str = "this is a test 1,2,3";
int length = CountAllNumbersAndChar(str);
Console.WriteLine(str);
Console.WriteLine(length);// met de methode maar kan handiger met onderstaand voor beeld
// Console.WriteLine(str.Length);
// int numbers = str.Count(Char.IsNumber); // de makelijkste makelijke manier
//Console.WriteLine(numbers);
int countnumber = CountNumbers(str) ;
Console.WriteLine(countnumber);
int countwords = words(str);
Console.WriteLine(countwords);
}
public static int CountAllNumbersAndChar(string str)
{
return str.Length;
}
public static int CountNumbers(string str)
{
return str.Count(Char.IsNumber);
}
public static int words(string str)
{
int words = str.Split().Count(str => str.All(Char.IsLetter));
}
}
}
but it still doesnt work could someone say me what I have to change ?
Is this what you want?
Console.WriteLine(CountAllNumbersAndChar(str));