SlideShare una empresa de Scribd logo
1 de 37
START
STRING
<BSCS-G-SECTION>
Presented by
 Muhammad Azeem
 Muhammad Maaz Usman
 Osman Asgher
 Umer Farooq
TEACHER: MA’AM SARAH
Generally speaking, a string is a sequence of characters
• Examples: “hello”, “high school”, “H2O”.
DEFINITION OF STRINGS
“Hello"
“High school"
DECLARATION OF STRINGS
The following instructions are all equivalent.
They declare x to be an object of type string,
and assign the string “high school” to it:
string x(“high school”);
DECLARATION OF STRINGS
string x= “high school”;
DECLARATION OF STRINGS
string x;
x=“high school”;
TYPE OF STRING
C++ provides following two types of string representations,
 The C-style character string (#include<string.h> Or #include<cstring>).
 The string class type introduced with Standard C++ (#include<string>).
 When we use C-string Functions so, we use this library.
(#include<string.h> Or #include<cstring>)
 When we use String Class Functions so, we use this library.
(#include<string>)
LIBRARY FOR C-STRING &
STRING CLASS
C-STRING
 Strings are arrays of chars. String literals are words surrounded by double quotation marks.
 The string in C programming language is actually a one-dimensional array of characters which is
terminated by a null character ‘0’. Thus a null-terminated string contains the characters that comprise
the string followed by a null.
 A string can be declared as a character array or with a string pointer.
 The following declaration and initialization create a string consisting of the word "Hello". To hold the
null character at the end of the array, the size of the character array containing the string is one more
than the number of characters in the word "Hello”.
OR
"This is a static string"
char aj[6]={‘H’,’E’,’L’,’L’,’O’,’0’} char aj[ ]={“HELLO”}
char *aj={“HELLO”}
 Following is the memory presentation of above defined string in C/C++:
 It's important to remember that there will be an extra character on the end on a string, literally a '0'
character, just like there is always a period at the end of a sentence. Since this string terminator is
unprintable, it is not counted as a letter, but it still takes up a space. Technically, in a fifty char array
you could only hold 49 letters and one null character at the end to terminate the string.
 Actually, you do not place the null character at the end of a string constant. The C compiler
automatically places the '0' at the end of the string when it initializes the array.
STRING MEMORY
INDEX 0 1 2 3 4 5
VARIABLE ‘H’ ‘A’ ‘L’ ‘L’ ‘O’ ‘0’
ADDRESS 0*23451 0*23452 0*23453 0*23454 0*23455 0*23456
Five char array you could only hold 4
letters and one null character at the end to
terminate the string.
Six char array you could only hold
6 letters and one null character at the end
to terminate the string.
C++ OPERATORS ARE NOT USE IN
C-STRING
 C++ Operator can’t be applied to them:
OPERATORS
Sr. No Function & Purpose
strcpy(s1, s2);
Copies string s2 into string s1.
strcat(s1, s2);
Concatenates string s2 onto the end of string s1.
strlen(s1);
Returns the length of string s1.
strcmp(s1, s2);
Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2.
C++ strncpy()
The strncpy() function in C++ copies a specified bytes of characters from source to destination.
strrev(s1, s2)
Reverse the string
C-STRING FUNCTIONS
strcpy(S1, S2);
COPIES STRING S2 INTO STRING S1.
C++ STRNCPY()
The strncpy() function in C++ copies a
specified bytes of characters from
source to destination.
strcat(S1, S2);
CONCATENATES(LINKS THINGS TOGETHER)
STRING S2 ONTO THE END OF STRING S1.
strlen(S1);
RETURNS THE LENGTH OF STRING S1.
String Comparison
This function compare 2 strings its returns
the ASCII difference of the first to non
matching char in both the strings.
Int strcmp(string1, string2)
If difference is equal to zero => srting1=string2
If difference is equal to +ve => srting1>string2
If difference is equal to -ve => srting1<string2
strrev(S1, S2)
Reverse the string
Without using strrev( )
To solve this problem, two standard
library functions strlen() and strcpy() are
used to calculate length and to copy string
respectively.
 The string class is a specialization of a more general template class called
basic_string (Pre-define Class)[Child class string, wstring).
 String is another container class (STL).
 To use string class, you have to include string header. - #include<string>
 Since defining a class in C++ is creating a new data type, string is derived data type.
STRING-CLASS
 Careless programmer can overrun the end of an array that holds a null terminated
string.
 For example, using strcpy()
 String class handle such issues
STRING IS SAFE THAN CHAR ARRAY
OPERATORS
WE USE ALL OPERATORS
USEFUL METHODS
assign( )
append( )
insert( )
replace( )
erase( )
find( )
rfind( )
compare( )
c_str( )
size( )
STRING CLASS FUNCTIONS
ASSIGN FUNCTION
Assigning a value to s1
APPEND TO STRING
Extends the string by appending
additional characters at the end of its
current value
INSERT INTO STRING
Inserts additional characters into the string
right before the character
Replace value in range
Assigns new_value to all the elements in the
range [first,last) that compare equal to
old_value.
ERASE CHARACTERS
FROM STRING
Erases part of the string, reducing its
length:
FIND CONTENT IN STRING
Searches the string for the first
occurrence of the sequence specified
by its arguments.
FIND LAST OCCURRENCE OF
CONTENT IN STRING
Searches the string for the last
occurrence of the sequence
specified by its arguments.
String Comparison
This function compare 2 strings its returns
the ASCII difference of the first to non
matching char in both the strings.
If difference is equal to 0 => srting1=string2
If difference is equal to +ve => srting1>string2
If difference is equal to -ve => srting1<string2
RETURN LENGTH OF STRING
Returns the length of the string, in terms
of bytes.
String in programming language in c or c++

Más contenido relacionado

La actualidad más candente (20)

Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
String C Programming
String C ProgrammingString C Programming
String C Programming
 
14 strings
14 strings14 strings
14 strings
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
C string
C stringC string
C string
 
Strings in C
Strings in CStrings in C
Strings in C
 
string in C
string in Cstring in C
string in C
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
String in c programming
String in c programmingString in c programming
String in c programming
 
String c
String cString c
String c
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Strings
StringsStrings
Strings
 
Strings
StringsStrings
Strings
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
 
String (Computer programming and utilization)
String (Computer programming and utilization)String (Computer programming and utilization)
String (Computer programming and utilization)
 
strings
stringsstrings
strings
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
 
C programming - String
C programming - StringC programming - String
C programming - String
 

Similar a String in programming language in c or c++

Lesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsLesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsJamesChristianGadian
 
C Programming Strings.docx
C Programming Strings.docxC Programming Strings.docx
C Programming Strings.docx8759000398
 
String & its application
String & its applicationString & its application
String & its applicationTech_MX
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
lecture-5 string.pptx
lecture-5 string.pptxlecture-5 string.pptx
lecture-5 string.pptxDilanAlmsa
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programmingmikeymanjiro2090
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiSowmya Jyothi
 
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxINDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxAbhimanyuChaure
 
C++ Strings.ppt
C++ Strings.pptC++ Strings.ppt
C++ Strings.pptDilanAlmsa
 

Similar a String in programming language in c or c++ (20)

String notes
String notesString notes
String notes
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
Unitii string
Unitii stringUnitii string
Unitii string
 
Lesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsLesson in Strings for C Programming Lessons
Lesson in Strings for C Programming Lessons
 
Week6_P_String.pptx
Week6_P_String.pptxWeek6_P_String.pptx
Week6_P_String.pptx
 
C Programming Strings.docx
C Programming Strings.docxC Programming Strings.docx
C Programming Strings.docx
 
String & its application
String & its applicationString & its application
String & its application
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
 
M C6java7
M C6java7M C6java7
M C6java7
 
lecture-5 string.pptx
lecture-5 string.pptxlecture-5 string.pptx
lecture-5 string.pptx
 
introduction to strings in c programming
introduction to strings in c programmingintroduction to strings in c programming
introduction to strings in c programming
 
lecture5.ppt
lecture5.pptlecture5.ppt
lecture5.ppt
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
 
Python data handling
Python data handlingPython data handling
Python data handling
 
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptxINDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
INDIAN INSTITUTE OF TECHNOLOGY KANPURESC 111M Lec13.pptx
 
Strings part2
Strings part2Strings part2
Strings part2
 
C++ Strings.ppt
C++ Strings.pptC++ Strings.ppt
C++ Strings.ppt
 
Strings1
Strings1Strings1
Strings1
 
string
stringstring
string
 

Más de Azeemaj101

Hospital Managment System Project Proposal
Hospital Managment System Project ProposalHospital Managment System Project Proposal
Hospital Managment System Project ProposalAzeemaj101
 
Registers and its type DLD
Registers and its type DLDRegisters and its type DLD
Registers and its type DLDAzeemaj101
 
Hospital Management system Final presentation
Hospital Management system Final presentationHospital Management system Final presentation
Hospital Management system Final presentationAzeemaj101
 
File Handling in Java Oop presentation
File Handling in Java Oop presentationFile Handling in Java Oop presentation
File Handling in Java Oop presentationAzeemaj101
 
Sampling Statistic presentation
Sampling Statistic presentationSampling Statistic presentation
Sampling Statistic presentationAzeemaj101
 
Hospital Management System Documentation Java
Hospital Management System Documentation Java Hospital Management System Documentation Java
Hospital Management System Documentation Java Azeemaj101
 
Essay and its Type
Essay and its TypeEssay and its Type
Essay and its TypeAzeemaj101
 
Operating System (OS)
Operating System (OS)Operating System (OS)
Operating System (OS)Azeemaj101
 

Más de Azeemaj101 (8)

Hospital Managment System Project Proposal
Hospital Managment System Project ProposalHospital Managment System Project Proposal
Hospital Managment System Project Proposal
 
Registers and its type DLD
Registers and its type DLDRegisters and its type DLD
Registers and its type DLD
 
Hospital Management system Final presentation
Hospital Management system Final presentationHospital Management system Final presentation
Hospital Management system Final presentation
 
File Handling in Java Oop presentation
File Handling in Java Oop presentationFile Handling in Java Oop presentation
File Handling in Java Oop presentation
 
Sampling Statistic presentation
Sampling Statistic presentationSampling Statistic presentation
Sampling Statistic presentation
 
Hospital Management System Documentation Java
Hospital Management System Documentation Java Hospital Management System Documentation Java
Hospital Management System Documentation Java
 
Essay and its Type
Essay and its TypeEssay and its Type
Essay and its Type
 
Operating System (OS)
Operating System (OS)Operating System (OS)
Operating System (OS)
 

Último

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Último (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

String in programming language in c or c++

  • 2.
  • 3. STRING <BSCS-G-SECTION> Presented by  Muhammad Azeem  Muhammad Maaz Usman  Osman Asgher  Umer Farooq TEACHER: MA’AM SARAH
  • 4. Generally speaking, a string is a sequence of characters • Examples: “hello”, “high school”, “H2O”. DEFINITION OF STRINGS “Hello" “High school"
  • 5. DECLARATION OF STRINGS The following instructions are all equivalent. They declare x to be an object of type string, and assign the string “high school” to it: string x(“high school”);
  • 6. DECLARATION OF STRINGS string x= “high school”;
  • 7. DECLARATION OF STRINGS string x; x=“high school”;
  • 8. TYPE OF STRING C++ provides following two types of string representations,  The C-style character string (#include<string.h> Or #include<cstring>).  The string class type introduced with Standard C++ (#include<string>).
  • 9.  When we use C-string Functions so, we use this library. (#include<string.h> Or #include<cstring>)  When we use String Class Functions so, we use this library. (#include<string>) LIBRARY FOR C-STRING & STRING CLASS
  • 10. C-STRING  Strings are arrays of chars. String literals are words surrounded by double quotation marks.  The string in C programming language is actually a one-dimensional array of characters which is terminated by a null character ‘0’. Thus a null-terminated string contains the characters that comprise the string followed by a null.  A string can be declared as a character array or with a string pointer.  The following declaration and initialization create a string consisting of the word "Hello". To hold the null character at the end of the array, the size of the character array containing the string is one more than the number of characters in the word "Hello”. OR "This is a static string" char aj[6]={‘H’,’E’,’L’,’L’,’O’,’0’} char aj[ ]={“HELLO”} char *aj={“HELLO”}
  • 11.  Following is the memory presentation of above defined string in C/C++:  It's important to remember that there will be an extra character on the end on a string, literally a '0' character, just like there is always a period at the end of a sentence. Since this string terminator is unprintable, it is not counted as a letter, but it still takes up a space. Technically, in a fifty char array you could only hold 49 letters and one null character at the end to terminate the string.  Actually, you do not place the null character at the end of a string constant. The C compiler automatically places the '0' at the end of the string when it initializes the array. STRING MEMORY INDEX 0 1 2 3 4 5 VARIABLE ‘H’ ‘A’ ‘L’ ‘L’ ‘O’ ‘0’ ADDRESS 0*23451 0*23452 0*23453 0*23454 0*23455 0*23456
  • 12. Five char array you could only hold 4 letters and one null character at the end to terminate the string.
  • 13. Six char array you could only hold 6 letters and one null character at the end to terminate the string.
  • 14. C++ OPERATORS ARE NOT USE IN C-STRING
  • 15.  C++ Operator can’t be applied to them: OPERATORS
  • 16. Sr. No Function & Purpose strcpy(s1, s2); Copies string s2 into string s1. strcat(s1, s2); Concatenates string s2 onto the end of string s1. strlen(s1); Returns the length of string s1. strcmp(s1, s2); Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2. C++ strncpy() The strncpy() function in C++ copies a specified bytes of characters from source to destination. strrev(s1, s2) Reverse the string C-STRING FUNCTIONS
  • 17. strcpy(S1, S2); COPIES STRING S2 INTO STRING S1.
  • 18. C++ STRNCPY() The strncpy() function in C++ copies a specified bytes of characters from source to destination.
  • 19. strcat(S1, S2); CONCATENATES(LINKS THINGS TOGETHER) STRING S2 ONTO THE END OF STRING S1.
  • 21. String Comparison This function compare 2 strings its returns the ASCII difference of the first to non matching char in both the strings. Int strcmp(string1, string2) If difference is equal to zero => srting1=string2 If difference is equal to +ve => srting1>string2 If difference is equal to -ve => srting1<string2
  • 23. Without using strrev( ) To solve this problem, two standard library functions strlen() and strcpy() are used to calculate length and to copy string respectively.
  • 24.  The string class is a specialization of a more general template class called basic_string (Pre-define Class)[Child class string, wstring).  String is another container class (STL).  To use string class, you have to include string header. - #include<string>  Since defining a class in C++ is creating a new data type, string is derived data type. STRING-CLASS
  • 25.  Careless programmer can overrun the end of an array that holds a null terminated string.  For example, using strcpy()  String class handle such issues STRING IS SAFE THAN CHAR ARRAY
  • 26. OPERATORS WE USE ALL OPERATORS
  • 27. USEFUL METHODS assign( ) append( ) insert( ) replace( ) erase( ) find( ) rfind( ) compare( ) c_str( ) size( ) STRING CLASS FUNCTIONS
  • 29. APPEND TO STRING Extends the string by appending additional characters at the end of its current value
  • 30. INSERT INTO STRING Inserts additional characters into the string right before the character
  • 31. Replace value in range Assigns new_value to all the elements in the range [first,last) that compare equal to old_value.
  • 32. ERASE CHARACTERS FROM STRING Erases part of the string, reducing its length:
  • 33. FIND CONTENT IN STRING Searches the string for the first occurrence of the sequence specified by its arguments.
  • 34. FIND LAST OCCURRENCE OF CONTENT IN STRING Searches the string for the last occurrence of the sequence specified by its arguments.
  • 35. String Comparison This function compare 2 strings its returns the ASCII difference of the first to non matching char in both the strings. If difference is equal to 0 => srting1=string2 If difference is equal to +ve => srting1>string2 If difference is equal to -ve => srting1<string2
  • 36. RETURN LENGTH OF STRING Returns the length of the string, in terms of bytes.

Notas del editor

  1. Delete this slide when you finish preparing the other slides.