DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Simple Parser Removing Nonalpha Maintain Spaces

02.10.2008
| 2140 views |
  • submit to reddit
        // quick parse; non alpha;

// OW - optional write

#include <iostream>
#include <string>
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);
}