An introductory example – HP Integrity NonStop J-Series User Manual
Page 48

Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
An Introductory Example
The following example calls on several essential features of the string classes. Basically, it shows
the steps
RWCString
would take to substitute a new version number for the old ones in a piece of
documentation.
#include
#include
#include
main(){
RWCString a; //1 create string object a
RWCRegexp re("V[0-9]\\.[0-9]+"); //2 define regular expression
while( a.readLine(cin) ){ //3 read standard input into a
a(re) = "V4.0"; //4 replace matched expression
cout << a << endl;
}
return 0;
}
Program Input:
This text describes V1.2. For more
information see the file install.doc.
The current version V1.2 implements...
Program Output:
This text describes V4.0. For more
information see the file install.doc.
The current version V4.0 implements...
The code here describes the activity of the class.
RWCString
creates a string object a, reads lines
from standard input into a, and searches a for a pattern matching the defined regular expression
"V[0-9]\\.[0-9]+". A match would be a version number between V0 and V9; for example, V1.2
and V1.22, but not V12.3. When a match is found, it is replaced with the string "V4.0"
The power of this operation lies in the expression:
a(re) = "V4.0";