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)