Advertisement
Imran_Mohammed

String Task

Jan 24th, 2021 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1.        // In The Name Of Allah
  2.  
  3. #include<bits/stdc++.h>
  4. #include<string.h>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10.     string s1,s2,s3;
  11.     // String Input With Space In CPP
  12.     getline(cin , s1);
  13.  
  14.     // Character Wise Output
  15.     for(int i=0; i<s1.size(); i++){
  16.         cout << s1[i] << " ";
  17.     }
  18.     cout << endl;
  19.  
  20.     //String Copy
  21.     s2 = s1;
  22.     cout << s2 << endl;
  23.  
  24.     // String Concatenation
  25.     s3 = s1+s2;
  26.     cout << s3 << endl;
  27.  
  28.     //Small letter to Capital Letter
  29.     for(int i=0; i<s1.size(); i++){
  30.         if(s[i]>=97 && s[i]<=122) s1[i] = 65 + s1[i] -97;
  31.         cout << s1[i] << " ";//Character Wise
  32.     }
  33.     cout << s1 << endl;// Full string
  34.  
  35.     //capital Letter to Small letter
  36.     for(int i=0; i<s1.size(); i++){
  37.         if( s1[i]>=65 && s[i]<=90 ) s1[i] = 97 + s1[i] -65;
  38.         cout << s1[i] << " ";//Character Wise
  39.     }
  40.     cout << s1 << endl;// Full string
  41.  
  42.     int a = 132,b;
  43.     string s,x="345";
  44.  
  45.     //Integer To String
  46.     s = to_string(a);
  47.     cout << s << endl;
  48.     s[0] = '2';//Replace
  49.     cout << s << endl;
  50.  
  51.     //String To Integer
  52.     b = stoi(x);
  53.     cout << b << endl;//345
  54.     b++;//Increasing
  55.     cout << b << endl;//346
  56.  
  57.     string p = "My Country Is Bangladesh";
  58.     cout << p.find("Bangladesh");//if find first size
  59.  
  60.     //Character Convert uppercase
  61.     char q = 'i';
  62.     q = toupper(q);
  63.     cout << q << endl;
  64.  
  65.      //Character Convert Lowercase
  66.     char r = 'M';
  67.     r = tolower(r);
  68.     cout << r << endl;
  69.  
  70.     //convert whole string into lowercase
  71.       transform(str.begin(), str.end(), str.begin(), [](unsigned char c){
  72.             return std::tolower(c);
  73.       });
  74.  
  75.     return 0;
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement