So in my class we are learning about strings. In this program, the goal is to reformat the text in a data file.
sample data file:
Here's a "TEST" file. (DateD 5 April, 2012)
Will this #*PrOGRAM+=@ that includes
!user-defined?!?> FUNCTIONS
really work? Only time will
tell.............
My program needs to delete the non alphanumeric characters that are at the beginning and end of each word.
For instance: "TEST" needs to be changed to TEST.
I can't use the isalpha to delete all nonalphanumeric characters because the ones inside each word are to be kept
For instance: !user-defined?!?> needs to be changed to user-defined
I've been trying to devise a way to do this but I can't figure this out.
Here's the code for the function.Thanks!
string characters(string text)
{
int n=text.length();
string newtext;
for (int i=0; i<n; i++)
if(isalnum(text[0])&&isalnum(text[n-1]))
{
newtext=newtext+text[i];
}
else
{
while (!isalnum(text[0]))
{
for (int j=1; j<n; j++)
text=newtext+text[j];
}
while (!isalnum(text[n-1]))
for(int k=0; k<n-2; k++)
text=newtext+text[k];
}
return newtext;
}