![]() |
How To Use String Functions Explain Briefly Details |
How To Use String Functions Explain Briefly Details
String: A String is a collection of characters.C++ Languages are not supported by String data types.
It can be used String char data types. String used single quotes and Double quotes.
The string can be stored single dimensional character array.
There are many predefined String functions in C++ Language.
C++ Language String index can be started 0 and String terminate null character('\0').
The string can be used in C++ Language predefined (string. h) header file.
String Examples
char s='icoderweb'('i','c','o','d','e','r','w','e','b','\0')
char s="icoderweb"
Important Topic in C++ Language
👉Data Types C++ Example in 2021
👉Decision Making if Statement in C++ with Example
👉C++ Operator with Example in 2021
String Function Details in C++
strcpy(s1,s2): String strcpy function can be used to copy the string here-string s2 is copied into string s1.
strcat(s1,s2): String function strcat can be used to add two strings here-string s2 concatenates at the end of string s1.
strcmp(s1,s2):String function strcmp can be used to compare two string.
strcmp string function returns 0 if string s1 and string s2 are the same.
strrev(s): String function strrev function can be used to reverse the string.
strip(s): A string function strip can be used to convert all the characters into the upper alphabet.
straw(s): String function straw can be used to convert all the characters into the lower alphabet.
strcmpi(s1,s2): The string function can be used to compare two strings.
but it ignores the case-sensitivity means 'x's and 'X' are treated as the same.
strcpy(s1,s2): String strcpy function can be used to copy the string here-string s2 is copied into string s1.
strcat(s1,s2): String function strcat can be used to add two strings here-string s2 concatenates at the end of string s1.
strcmp(s1,s2):String function strcmp can be used to compare two string.
strcmp string function returns 0 if string s1 and string s2 are the same.
strrev(s): String function strrev function can be used to reverse the string.
strip(s): A string function strip can be used to convert all the characters into the upper alphabet.
straw(s): String function straw can be used to convert all the characters into the lower alphabet.
strcmpi(s1,s2): The string function can be used to compare two strings.
but it ignores the case-sensitivity means 'x's and 'X' are treated as the same.
How To Create String in C++ Language
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s1[200]="icoderweb";
char s2[200]='icoderweb';
cout<<"Website Name:"<<s1<<"\n";
cout<<"Website Name:"<<s2;
return 0;
}
*****OUTPUT*****
Website Name:icoderweb
Website Name:icoderweb
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s1[200]="icoderweb";
char s2[200]='icoderweb';
cout<<"Website Name:"<<s1<<"\n";
cout<<"Website Name:"<<s2;
return 0;
}
*****OUTPUT*****
Website Name:icoderweb
Website Name:icoderweb
How To Use String len Function in C++ Language?
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s[100]="icoderweb";
cout<<"String Lenght:"<<strlen(s);
return 0;
}
*****OUTPUT*****
String Lenght:9
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s[100]="icoderweb";
cout<<"String Lenght:"<<strlen(s);
return 0;
}
*****OUTPUT*****
String Lenght:9
How To Use String strcpy Function in C++ Language?
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s1[100]="Python";
char s2[100]="Java";
strcpy(s1,s2);
cout<<"Copy String Name:"<<s1;
return 0;
}
*****OUTPUT*****
Copy String Name:Java
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s1[100]="Python";
char s2[100]="Java";
strcpy(s1,s2);
cout<<"Copy String Name:"<<s1;
return 0;
}
*****OUTPUT*****
Copy String Name:Java
How To Use String strcmp Function in C++ Language?
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char user1[100]="icoderweb";
char pass1[100]="12345";
char user2[100];
char pass2[100];
cout<<"Enter Username:";
gets(user2);
cout<<"Enter Password:";
gets(pass2);
if(strcmp(user1,user2)==0&&strcmp(pass1,pass2)==0)
cout<<"Login Successfully";
else
cout<<"Wrong username or password";
}
*****OUTPUT*****
Enter Username:icoderweb
Enter Password:12345
Login Successfully
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
*****OUTPUT*****
Enter Username:icoderweb
Enter Password:12345
Login Successfully
How To Use String strrev Function in C++ Language?
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s[100]="icoderweb";
cout<<"Reverse String Name:"
<<strrev(s);
return 0;
}
*****OUTPUT*****
Reverse String Name:bewredoci
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s[100]="icoderweb";
cout<<"Reverse String Name:"
<<strrev(s);
return 0;
}
*****OUTPUT*****
Reverse String Name:bewredoci
How To Use String strip Function in C++ Language?
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s[100]="icoderweb";
cout<<"Uper String Name:"<<strupr(s);
return 0;
}
*****OUTPUT*****
Uper String Name:ICODERWEB
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s[100]="icoderweb";
cout<<"Uper String Name:"<<strupr(s);
return 0;
}
*****OUTPUT*****
Uper String Name:ICODERWEB
How To Use String strlwr Function in C++ Language?
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s[100]="ICODERWEB";
cout<<"Lower String Name:"<<strlwr(s));
return 0;
}
*****OUTPUT*****
Lower String Name:icoderweb
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
char s[100]="ICODERWEB";
cout<<"Lower String Name:"<<strlwr(s));
return 0;
}
*****OUTPUT*****
Lower String Name:icoderweb