+ 1
string = "D&E"
for char in string:
chr.isalpha() method
if char.isalpha():
only_alpha += char
print(only_alpha)
+ 1
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string tmp = "D&E";
char c[3];
strcpy(c, tmp.c_str());
}
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;
}
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";
}