+ 1
string = "D&E" for char in string: chr.isalpha() method if char.isalpha(): only_alpha += char print(only_alpha)
9th Apr 2022, 7:56 AM
Abhivarshini Maddala
Abhivarshini Maddala - avatar
+ 1
#include <iostream> #include <cstring> using namespace std; int main() { string tmp = "D&E"; char c[3]; strcpy(c, tmp.c_str()); }
9th Apr 2022, 8:07 AM
Abhivarshini Maddala
Abhivarshini Maddala - avatar
0
// If you prefer inplace: #include <iostream> #include <algorithm> #include <string> #include <cctype> int main() { std::string s("D&123G,!&878"); s.erase(std::remove_if(s.begin(), s.end(), [](const char& c) { return !::isalpha(static_cast<unsigned char>(c));}), s.end()); std::cout << s << '\n'; return 0; }
11th Apr 2022, 1:35 AM
Flash
0
#include <iostream> #include <cstring> using namespace std; int main() { string tmp = "D&E"; char c[3]; strcpy(c, tmp.c_str()); for(int i=0;i<strlen(c);i++) cout<<c[i]<<"\n"; }
11th Apr 2022, 5:32 AM
TeaserCode