| A good way for you to understand the substitute() method is to play around
with it by using this test program. The program takes 3 to 5 arguments
as follows:
java substituteExample
regex substitution input [sub limit] [interpolation limit]
regex - A regular expression used to find parts of the input to be
substituted.
sub limit - An optional argument limiting the number of substitutions.
If no limit is given, the limit used is Util.SUBSTITUTE_ALL.
input - A string to be used as input for substitute().
interpolation limit - An optional argument limiting the number of
interpolations performed.
Try the following command line for a simple example of subsitute().
It changes (2,3) to (3,2) in the input.
java substituteExample '\(2,3\)' '(3, 2)' '(1,2) (2,3) (4,5)'
The following command line shows the substitute limit at work. It
changed the first four 1's in the input to 4's.
java substituteExample '1' '4' '381298175 1111'
|