. NET Study notes----2015-07-10 (Basic review and Exercise 08)

Source: Internet
Author: User

1, there is the following string: ""Patient:"doctor, I have a bad cough. "Doctor:"How much do you remember? "Patient:"75 years old. "Doctor:"20-year-old cough?"Patient:"no cough. "Doctor:"Do you cough when you are 40 years old? "Patient:"and not coughing. "Doctor:"so now don't cough, but also wait for what when cough? ""】。

Requirements: Please count the number of occurrences of the word "cough" in this word, and the index position of each "cough".

2, will the string " Hello world ! " both spaces are stripped, and all other spaces in it are replaced with a single space, and the output is: Hello world ! .

        Static voidMain (string[] args) {            stringstr ="Hello world! "; stringNewstr =Str.            Trim (); string[] s = str. Split (New Char[] {' '}, Stringsplitoptions.removeemptyentries); stringSS =string. Join (" ", s);            Console.WriteLine (ss);        Console.readkey (); }

3.

Make a console applet. Requirements: The user can enter the name of each student in the console, and when the user enters quit(case insensitive), the program stops accepting the user's input and displays the number of students entered by the user, as well as the name of each student.

        Static voidMain (string[] args) {List<string> namelist =Newlist<string>();  while(true) {Console.WriteLine ("Please enter your name:"); stringName =Console.ReadLine ();                Namelist.add (name); if(name. ToLower ()) = ="quit")                {                     Break; }} Console.WriteLine ("you entered a total of: {0} Students, the names are:", Getnamesnum (NameList)-1);  for(inti =0; I < namelist.count-1; i++) {Console.WriteLine (namelist[i]);        } console.readkey (); }        /// <summary>        ///iterating through a collection of strings/// </summary>        /// <param name= "names" >the collection to traverse</param>        /// <returns>returns the number of elements in a collection</returns>        ///        Static intGetnamesnum (list<string>names) {            returnnames.        Count; }

. NET Study notes----2015-07-10 (Basic review and Exercise 08)

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.