SlideShare una empresa de Scribd logo
1 de 8
Descargar para leer sin conexión
M.Jancypriya
Assistant Professor
Department of computer Applications
Bon Secours College for Women,
Thanjavur
Sequence of characters.Built-in functions
are not supported by C++.
Using string class,
#include<string>
Creating string objects
Reading string objects from keyboard
Displaying string objects to the screen
Finding a substring from a string
Modifying string
Adding objects of string
Comparing strings
Accessing characters of a string
Obtaining the size or length of a string
String s1; // no args
String s2(“xyz”); // one arg
S1=s2 // assigning obj
S3=“abc”+s2 // concatenating string
Cin>>s1; // reading a word through
keyboard
S3+=s1; // overloading +op s3=s3+s1
 strcpy(str1, str2): Copies string str2 into string str1.
 strcat(str1, str2): Concatenates string str2 onto the
end of string str1.
 strlen(str1): Returns the length of string str1.
 strcmp(str1, str2): Returns 0 if str1 and str2 are the
same; less than 0 if str1<str2; greater than 0 if
str1>str2.
 strstr(str1, str2): Returns a pointer to the first
occurrence of string str2 in string str1
append():This function appends a part of
a string to another string.
erase():This function removes character
as specified.
Insert() : insert a character at specified
location.
Replace()- replace the specific character
with a given string.
 void relational_operation(string s1, string s2)
 {
 string s3 = s1 + s2;

 if(s1 != s2)
 cout << s1 << " is not equal to " << s2 << endl;

 if(s1 > s2)
 cout << s1 << " is greater than " << s2 << endl;

 else if(s1 < s2)
 cout << s1 << " is smaller than " << s2 << endl;

 if(s3 == s1 + s2)
 cout << s3 << " is equal to " << s1 + s2 << endl;

 }
// Main function
int main()
{
string s1("Geeks");
string s2("forGeeks");
relational_operation(s1,s2);
return 0;
}
Output:
Geeks is not equal to forGeeks
Geeks is smaller than forGeeks
GeeksforGeeks is equal to GeeksforGeeks

Más contenido relacionado

La actualidad más candente

Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++Sachin Yadav
 
Binary operator overloading
Binary operator overloadingBinary operator overloading
Binary operator overloadingBalajiGovindan5
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++•sreejith •sree
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
Programming in Java: Library Classes
Programming in Java: Library ClassesProgramming in Java: Library Classes
Programming in Java: Library ClassesMartin Chapman
 
file handling c++
file handling c++file handling c++
file handling c++Guddu Spy
 
Command line arguments
Command line argumentsCommand line arguments
Command line argumentsAshok Raj
 
Java string , string buffer and wrapper class
Java string , string buffer and wrapper classJava string , string buffer and wrapper class
Java string , string buffer and wrapper classSimoniShah6
 
What is Tuple in python? | Python Tuple Tutorial | Edureka
What is Tuple in python? | Python Tuple Tutorial | EdurekaWhat is Tuple in python? | Python Tuple Tutorial | Edureka
What is Tuple in python? | Python Tuple Tutorial | EdurekaEdureka!
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanKavita Ganesan
 

La actualidad más candente (20)

Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
Binary operator overloading
Binary operator overloadingBinary operator overloading
Binary operator overloading
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
Tuples in Python
Tuples in PythonTuples in Python
Tuples in Python
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
StringTokenizer in java
StringTokenizer in javaStringTokenizer in java
StringTokenizer in java
 
Programming in Java: Library Classes
Programming in Java: Library ClassesProgramming in Java: Library Classes
Programming in Java: Library Classes
 
file handling c++
file handling c++file handling c++
file handling c++
 
Strings
StringsStrings
Strings
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
 
String Handling
String HandlingString Handling
String Handling
 
Constants in java
Constants in javaConstants in java
Constants in java
 
Java string , string buffer and wrapper class
Java string , string buffer and wrapper classJava string , string buffer and wrapper class
Java string , string buffer and wrapper class
 
What is Tuple in python? | Python Tuple Tutorial | Edureka
What is Tuple in python? | Python Tuple Tutorial | EdurekaWhat is Tuple in python? | Python Tuple Tutorial | Edureka
What is Tuple in python? | Python Tuple Tutorial | Edureka
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita Ganesan
 
Python list
Python listPython list
Python list
 

Similar a Manipulating strings

Similar a Manipulating strings (20)

C++ Strings.ppt
C++ Strings.pptC++ Strings.ppt
C++ Strings.ppt
 
String in programming language in c or c++
String in programming language in c or c++String in programming language in c or c++
String in programming language in c or c++
 
lecture-5 string.pptx
lecture-5 string.pptxlecture-5 string.pptx
lecture-5 string.pptx
 
manipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptxmanipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptx
 
Strings part2
Strings part2Strings part2
Strings part2
 
Strings
StringsStrings
Strings
 
Unitii string
Unitii stringUnitii string
Unitii string
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Manipulation of Strings
Manipulation of StringsManipulation of Strings
Manipulation of Strings
 
strings
stringsstrings
strings
 
Module-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdfModule-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdf
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
Computer Programming- Lecture 6
Computer Programming- Lecture 6Computer Programming- Lecture 6
Computer Programming- Lecture 6
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
 
String in c programming
String in c programmingString in c programming
String in c programming
 
Strings.ppt
Strings.pptStrings.ppt
Strings.ppt
 
Implementation Of String Functions In C
Implementation Of String Functions In CImplementation Of String Functions In C
Implementation Of String Functions In C
 
String functions
String functionsString functions
String functions
 
Strings1
Strings1Strings1
Strings1
 
Strings
StringsStrings
Strings
 

Más de Jancypriya M

Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computerJancypriya M
 
Library automation software
Library automation softwareLibrary automation software
Library automation softwareJancypriya M
 
Flip Flop and Its Types
Flip Flop and Its TypesFlip Flop and Its Types
Flip Flop and Its TypesJancypriya M
 
Introduction to pagemaker
Introduction to pagemakerIntroduction to pagemaker
Introduction to pagemakerJancypriya M
 
Standard template library
Standard template libraryStandard template library
Standard template libraryJancypriya M
 

Más de Jancypriya M (8)

Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computer
 
Library automation software
Library automation softwareLibrary automation software
Library automation software
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Flip Flop and Its Types
Flip Flop and Its TypesFlip Flop and Its Types
Flip Flop and Its Types
 
Corel draw tools
Corel draw toolsCorel draw tools
Corel draw tools
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Introduction to pagemaker
Introduction to pagemakerIntroduction to pagemaker
Introduction to pagemaker
 
Standard template library
Standard template libraryStandard template library
Standard template library
 

Último

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Último (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 

Manipulating strings

  • 1. M.Jancypriya Assistant Professor Department of computer Applications Bon Secours College for Women, Thanjavur
  • 2. Sequence of characters.Built-in functions are not supported by C++. Using string class, #include<string>
  • 3. Creating string objects Reading string objects from keyboard Displaying string objects to the screen Finding a substring from a string Modifying string Adding objects of string Comparing strings Accessing characters of a string Obtaining the size or length of a string
  • 4. String s1; // no args String s2(“xyz”); // one arg S1=s2 // assigning obj S3=“abc”+s2 // concatenating string Cin>>s1; // reading a word through keyboard S3+=s1; // overloading +op s3=s3+s1
  • 5.  strcpy(str1, str2): Copies string str2 into string str1.  strcat(str1, str2): Concatenates string str2 onto the end of string str1.  strlen(str1): Returns the length of string str1.  strcmp(str1, str2): Returns 0 if str1 and str2 are the same; less than 0 if str1<str2; greater than 0 if str1>str2.  strstr(str1, str2): Returns a pointer to the first occurrence of string str2 in string str1
  • 6. append():This function appends a part of a string to another string. erase():This function removes character as specified. Insert() : insert a character at specified location. Replace()- replace the specific character with a given string.
  • 7.  void relational_operation(string s1, string s2)  {  string s3 = s1 + s2;   if(s1 != s2)  cout << s1 << " is not equal to " << s2 << endl;   if(s1 > s2)  cout << s1 << " is greater than " << s2 << endl;   else if(s1 < s2)  cout << s1 << " is smaller than " << s2 << endl;   if(s3 == s1 + s2)  cout << s3 << " is equal to " << s1 + s2 << endl;   }
  • 8. // Main function int main() { string s1("Geeks"); string s2("forGeeks"); relational_operation(s1,s2); return 0; } Output: Geeks is not equal to forGeeks Geeks is smaller than forGeeks GeeksforGeeks is equal to GeeksforGeeks