Over a million developers have joined DZone.

Simple Parser Removing Nonalpha Maintain Spaces

·
// quick parse; non alpha;


// OW - optional write

#include 
#include 
using namespace std;


int main()
{    
    string line = "Hey, This-- this is the test line."; // test string
    // line = fakeFunction(line);

// !== start fake function ( argument = line )
    string lb; // line buffer
    for (int i = 0; i < line.length(); i++) {
    // scroll through each character, push only characters
    // and spaces on the line buffer   
      if ( (isalpha(line[i])) || (isspace(line[i])) ){ // condition     
// OW if ( (isalpha(line.at(i))) || (isspace(line.at(i))) ) // condition     
        line[i] = tolower(line[i]); //action 1
        lb.append(line,i,1); //action 2        
      }  
    } // end for

cout << lb << endl; // test output line... just delete
//  !== end fake function (return lb)
    
    system("PAUSE");
    
    
    return(0);
}

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}