foreach-(iterates through the characters in an array or loop for information)

Source: Internet
Author: User

Namespace ConsoleApplication2
{
Class Program
{//letter Letter Gigit digit Symbol
static void Main (string[] args)
{
Console.WriteLine ("Please enter character");
string s = Console.ReadLine ();//input string is received with S
int letter = 0;//The initial number of letters is 0
int gigit = 0; The number of first digits is 0
int symbol = 0;//The number of first characters is 0
foreach (char c in s)
The {//foreach statement is used to iterate through the collection to get the information you want, syntax foreach (element type C int Traversal object s)
if (char. Isletter (c)) letter++;//extract the letters from the string
else if (char. IsDigit (c)) gigit++;//extracts a number from a string
else symbol++;//extracting symbols from a string
}
Console.WriteLine ("Number of letters:" + letter + "\ T" + "number:" + gigit + "\ T" + "number of characters:" + symbol);//Output
Console.ReadLine ();
}
}
}

foreach-(iterates through the characters in an array or loop for information)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.