1 / 2

Session-8 CSIT 121 Spring 2006

Session-8 CSIT 121 Spring 2006. Chapter 3 continued Text string processing (Functions to search for a sub-string, count the length of names and compare two strings) Example demo program Lesson 3-5 Exercises 1,2,3

maxine
Télécharger la présentation

Session-8 CSIT 121 Spring 2006

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Session-8 CSIT 121 Spring 2006 • Chapter 3 continued • Text string processing (Functions to search for a sub-string, count the length of names and compare two strings) • Example demo program • Lesson 3-5 Exercises 1,2,3 • Lab sheet : Extend Exercise 3 so that your program searches for a pattern “ob” in your full name and reports “pattern found” or “not found” on the screen

  2. Demo Program for Strings • void main () • { • string myname, yourname; • int mylength, yourlength; • int pos; • cout<<"Enter first user's full name"; • getline(cin,myname); • cout<<"Enter second user's full name"; • getline(cin,yourname); • mylength = int (myname.length()); • yourlength = int (yourname.length()); • cout<<"My name is "<<mylength<<" characters long"<<endl; • cout<<"Your name is "<<yourlength<<" characters long"<<endl; • if (myname>yourname) cout<<"My name is longer"<<endl; • else cout<<"Your name is longer"<<endl; • pos = myname.find('Z'); • if (pos != -1) cout<<"Zub occurs at position "<<pos<<endl; cout<<myname.substr(5,6)<<endl; • }

More Related