The following code example demonstrates simple string parsing using the
Example
В | ![]() |
---|---|
// regex_parse.cpp // compile with: /clr #using <system.dll> using namespace System; using namespace System::Text::RegularExpressions; int main( ) { int words = 0; String^ pattern = "[a-zA-Z]*"; Console::WriteLine( "pattern : '{0}'", pattern ); Regex^ regex = gcnew Regex( pattern ); String^ line = "one\ttwo three:four,five six seven"; Console::WriteLine( "text : '{0}'", line ); for( Match^ match = regex->Match( line ); match->Success; match = match->NextMatch( ) ) { if( match->Value->Length > 0 ) { words++; Console::WriteLine( "{0}", match->Value ); } } Console::WriteLine( "Number of Words : {0}", words ); return 0; } |