SlideShare una empresa de Scribd logo
1 de 15
1
String
2
“A Collection of characters written in double quotation marks.”
String Declaration:
C++ stores a string as an array of characters.
Syntax:
char array_name[ length ];
String Initialization:
The syntax of String Initialization.
Syntax:
char array_name[ length ] = value;
char: It indicates the type of an array.
array_name: It indicates the name of an array.
length: It indicates the number of memory locations in the array.
value: It indicates the value of initialization in string.
String Input
A string value can be input from the user using different ways.
The “cin” object:
The cin object is used to input a string value without any spaces.
Syntax:
cin >> str;
The “cin.getline( )” object:
The cin.getline() object is used to input a string value including spaces.
Syntax:
cin.getline ( str, len );
The “cin.get( )” object:
The cin.get() object is used to input a single character.
Syntax:
cin.get ( ch );
str: Name of string variable.
len: Length of string variable.
ch: Any character.
3
String Input: ( Example )#include< iostream >
using namespace std;
void main()
{
char name[ 5 ];
char c;
count << "Enter your Name = ";
// "cin" Object
cin >> name; // Simple input
cout << endl << "Your Name: " << name << endl;
// "cin.getline ( str, len );" Objet
cin.getline( name, 90 ); // Take input including Space
cout << endl << "Your Name: " << name << endl;
// "cin.get ( ch );" Object
cin.get( c ); //Take one character
cout << endl << "Your Name: " << c << endl;
system ( "pause" );
}
4
Array Of Strings
Two - dimensional array of characters.
Each row represents one string.
Each character stored in separate index.
Syntax:
char str[rows][cols];
There are two methods for initializing
1. By assigning individual characters
2. By assigning complete string
For Input:
cin>>str[0];
For Output:
cout<<str[0];
5
String Functions:
memchr()
 Used to search a byte with particular value in buffer.
 SYNTAX : memchr( buffer, ch, size);
Memcmp()
 Used to compare each successive byte with corresponding
byte.
• SYNTAX : memcmp( buffer1, buffer2, size);
Memcpy()
 Used to copy the number of specified characters from 1st
buffer to 2nd buffer and returns the 1st buffer.
 SYNTAX : memcpy(buffer2 ,buffer1 ,size); 6
String Functions:
• strcat( ):
The strcat() function is used to append a copy of one string to
the end of second string. It also terminates the resulting
string with null character.
Syntax:
strcat ( srt1, str2 );
• strncat( ):
The strncat() function is used to append the specific number
of characters of one string to the end of second string. It also
terminates the resulting string with null character.
Syntax:
strncat ( srt1, str2, n ); 7
String Functions:
• strchr( ):
The strchr() function is used to find the first occurrence of
a character in string and returns a pointer to this character.
It returns NULL is character is not found.
Syntax:
strchr ( str, ch );
• strrchr( ):
The strrchr() function is used to find the last occurrence of
a character in string and returns a pointer to this character.
It returns NULL is character is not found.
Syntax:
strrchr ( str, ch ); 8
String Functions:
• stricmp( ):
The stricmp() function is used to compare two string character
by character.
Syntax:
stricmp ( str1, str1 );
• Strncmp( )
Use : compare the specified number of character in two string.
Syntax:
strncmp(str1, str 2, n);
• Strcoll( )
Use : Compare two string values the collating sequence
specified by set locale function and indicating the relationship.
Syntax:
strcoll(str1, str 2);
9
String Functions:
• Strcpy( )
Use : copy one string to another including the terminating null
character.
Syntax:
Strcpy (str1, str2);
• strncpy( )
Use : copy one string to another including the terminating null
character. It only copies only specified character.
Syntax:
strncpy (str1, str2, n);
• strlen( )
Use: find length of string.
Syntax: strlen (str);
10
String Functions:
strstr( ):
The strstr() function is used to find the first occurrence of second
string within first string and returns a pointer to this character.
It returns NULL if occurrence is not found.
Syntax:
strstr ( str1, str2 );
strpbrk( ):
The strpbrk() function locates the first occurrence in the string pointed
to by s1 of any character from the string pointed to by s2. It returns
NULL if occurrence is not found.
Syntax:
strpbrk (const char *s1, const char *s2);
11
String Functions:
12
strspn( ):
• The strspn() function compute length of maximum initial
segment of the string pointed by s1 which consist entirely of
character from the string pointed to by s2.
Syntax:
Strspn ( str1, str2 );
strerror( ):
The function takes an error number as parameter and returns a
pointer to error message associated with that error number.
The function can be called with global variable errno declared
in errno.h.
Syntax:
strerror ( errno );
String Functions:
• strrev( ):
• The function reverse all the characters in a string except the null character.
• Syntax:
strrev( str );
strset( ):
The function set all the characters in a string to the specified character accept the
null character.
Syntax: strset( str, ch );
strlwr( ):
The function converts all the characters of a string to lowercase.
Syntax:
strlwr( str );
strupr( ):
The function converts all the characters of a string to uppercase.
Syntax:
strupr( str );
13
Hello frands Question Poch lo
14
15

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Strings
StringsStrings
Strings
 
05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
 
String c
String cString c
String c
 
String in c programming
String in c programmingString in c programming
String in c programming
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in C
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
 
strings
stringsstrings
strings
 
Strings in c
Strings in cStrings in c
Strings in c
 
Strings in C
Strings in CStrings in C
Strings in C
 
Strings
StringsStrings
Strings
 
string in C
string in Cstring in C
string in C
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++
 
Headerfiles
HeaderfilesHeaderfiles
Headerfiles
 
Strings1
Strings1Strings1
Strings1
 
String & its application
String & its applicationString & its application
String & its application
 
Team 1
Team 1Team 1
Team 1
 

Similar a String handling

String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++Fahim Adil
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiSowmya Jyothi
 
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
 
Python Strings Methods
Python Strings MethodsPython Strings Methods
Python Strings MethodsMr Examples
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdfssusere19c741
 
manipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptxmanipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptxShowribabuKanta
 
PPS Presentation.pptx
PPS Presentation.pptxPPS Presentation.pptx
PPS Presentation.pptxSharan288059
 
06 -working_with_strings
06  -working_with_strings06  -working_with_strings
06 -working_with_stringsHector Garzo
 
L14 string handling(string buffer class)
L14 string handling(string buffer class)L14 string handling(string buffer class)
L14 string handling(string buffer class)teach4uin
 
16 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp0216 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp02Abdul Samee
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTSasideepa
 

Similar a String handling (20)

Strings
StringsStrings
Strings
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++
 
Strings
StringsStrings
Strings
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
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
 
Python Strings Methods
Python Strings MethodsPython Strings Methods
Python Strings Methods
 
0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf0-Slot21-22-Strings.pdf
0-Slot21-22-Strings.pdf
 
C q 3
C q 3C q 3
C q 3
 
Header file.pptx
Header file.pptxHeader file.pptx
Header file.pptx
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
manipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptxmanipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptx
 
PPS Presentation.pptx
PPS Presentation.pptxPPS Presentation.pptx
PPS Presentation.pptx
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
06 -working_with_strings
06  -working_with_strings06  -working_with_strings
06 -working_with_strings
 
String notes
String notesString notes
String notes
 
Unitii string
Unitii stringUnitii string
Unitii string
 
L14 string handling(string buffer class)
L14 string handling(string buffer class)L14 string handling(string buffer class)
L14 string handling(string buffer class)
 
Lecture 3.pptx
Lecture 3.pptxLecture 3.pptx
Lecture 3.pptx
 
16 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp0216 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp02
 
CPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPTCPSTRINGSARGAVISTRINGS.PPT
CPSTRINGSARGAVISTRINGS.PPT
 

Último

Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 

Último (20)

Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
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.
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 

String handling

  • 1. 1
  • 2. String 2 “A Collection of characters written in double quotation marks.” String Declaration: C++ stores a string as an array of characters. Syntax: char array_name[ length ]; String Initialization: The syntax of String Initialization. Syntax: char array_name[ length ] = value; char: It indicates the type of an array. array_name: It indicates the name of an array. length: It indicates the number of memory locations in the array. value: It indicates the value of initialization in string.
  • 3. String Input A string value can be input from the user using different ways. The “cin” object: The cin object is used to input a string value without any spaces. Syntax: cin >> str; The “cin.getline( )” object: The cin.getline() object is used to input a string value including spaces. Syntax: cin.getline ( str, len ); The “cin.get( )” object: The cin.get() object is used to input a single character. Syntax: cin.get ( ch ); str: Name of string variable. len: Length of string variable. ch: Any character. 3
  • 4. String Input: ( Example )#include< iostream > using namespace std; void main() { char name[ 5 ]; char c; count << "Enter your Name = "; // "cin" Object cin >> name; // Simple input cout << endl << "Your Name: " << name << endl; // "cin.getline ( str, len );" Objet cin.getline( name, 90 ); // Take input including Space cout << endl << "Your Name: " << name << endl; // "cin.get ( ch );" Object cin.get( c ); //Take one character cout << endl << "Your Name: " << c << endl; system ( "pause" ); } 4
  • 5. Array Of Strings Two - dimensional array of characters. Each row represents one string. Each character stored in separate index. Syntax: char str[rows][cols]; There are two methods for initializing 1. By assigning individual characters 2. By assigning complete string For Input: cin>>str[0]; For Output: cout<<str[0]; 5
  • 6. String Functions: memchr()  Used to search a byte with particular value in buffer.  SYNTAX : memchr( buffer, ch, size); Memcmp()  Used to compare each successive byte with corresponding byte. • SYNTAX : memcmp( buffer1, buffer2, size); Memcpy()  Used to copy the number of specified characters from 1st buffer to 2nd buffer and returns the 1st buffer.  SYNTAX : memcpy(buffer2 ,buffer1 ,size); 6
  • 7. String Functions: • strcat( ): The strcat() function is used to append a copy of one string to the end of second string. It also terminates the resulting string with null character. Syntax: strcat ( srt1, str2 ); • strncat( ): The strncat() function is used to append the specific number of characters of one string to the end of second string. It also terminates the resulting string with null character. Syntax: strncat ( srt1, str2, n ); 7
  • 8. String Functions: • strchr( ): The strchr() function is used to find the first occurrence of a character in string and returns a pointer to this character. It returns NULL is character is not found. Syntax: strchr ( str, ch ); • strrchr( ): The strrchr() function is used to find the last occurrence of a character in string and returns a pointer to this character. It returns NULL is character is not found. Syntax: strrchr ( str, ch ); 8
  • 9. String Functions: • stricmp( ): The stricmp() function is used to compare two string character by character. Syntax: stricmp ( str1, str1 ); • Strncmp( ) Use : compare the specified number of character in two string. Syntax: strncmp(str1, str 2, n); • Strcoll( ) Use : Compare two string values the collating sequence specified by set locale function and indicating the relationship. Syntax: strcoll(str1, str 2); 9
  • 10. String Functions: • Strcpy( ) Use : copy one string to another including the terminating null character. Syntax: Strcpy (str1, str2); • strncpy( ) Use : copy one string to another including the terminating null character. It only copies only specified character. Syntax: strncpy (str1, str2, n); • strlen( ) Use: find length of string. Syntax: strlen (str); 10
  • 11. String Functions: strstr( ): The strstr() function is used to find the first occurrence of second string within first string and returns a pointer to this character. It returns NULL if occurrence is not found. Syntax: strstr ( str1, str2 ); strpbrk( ): The strpbrk() function locates the first occurrence in the string pointed to by s1 of any character from the string pointed to by s2. It returns NULL if occurrence is not found. Syntax: strpbrk (const char *s1, const char *s2); 11
  • 12. String Functions: 12 strspn( ): • The strspn() function compute length of maximum initial segment of the string pointed by s1 which consist entirely of character from the string pointed to by s2. Syntax: Strspn ( str1, str2 ); strerror( ): The function takes an error number as parameter and returns a pointer to error message associated with that error number. The function can be called with global variable errno declared in errno.h. Syntax: strerror ( errno );
  • 13. String Functions: • strrev( ): • The function reverse all the characters in a string except the null character. • Syntax: strrev( str ); strset( ): The function set all the characters in a string to the specified character accept the null character. Syntax: strset( str, ch ); strlwr( ): The function converts all the characters of a string to lowercase. Syntax: strlwr( str ); strupr( ): The function converts all the characters of a string to uppercase. Syntax: strupr( str ); 13
  • 14. Hello frands Question Poch lo 14
  • 15. 15