Write a program that removes all non-alphabetic characters from the given input.

Ex: If the input is:

-Hello, 1 world$!
the output is:

Helloworld

Your program must define and call the following function. The function should return a string representing the input string without non-alphabetic characters.

string RemoveNonAlpha(string userString)

#include
#include
#include
using namespace std;

/* Define your function here */
string RemoveNonAlpha(string userString)
{
char ch;
string str;
int length;
length = userString.length();
for (int i = 0; i <= length; i++)
{
ch = userString;
if (isalpha(ch))
{
str += ch;
}
}
return str;
}

int main()
{
// Local Variables
string input;

getline(cin, input);

cout << RemoveNonAlpha(input) << endl;

return 0;
}

my code is wrong but I can't seem to figure out the problem becuase i am getting no output

Respuesta :

The program that removes all non-alphabetic characters from a given input is as follows:

import re

def onlyalphabet(text):

   

    text = re.sub("[^a-zA-Z]+", "",text)

    return text

print(onlyalphabet("*#126vinc"))

Code explanation:

The code is written in python.

  • The first line of code, we imported regex module.
  • A function "onlyalphabet" is declared and accept the arguments "text".
  • The argument then check for only alphabets.
  • Then it returns the text
  • Finally, we print the function with the argument

learn more on python here: https://brainly.com/question/14468239

ACCESS MORE
EDU ACCESS
Universidad de Mexico