Page 1 of 1

Replace recursively

Posted: Sat Feb 02, 2008 7:57 am
by Flatron
Hi!

I have a lot of variables, and I would like to make a Get function for each. E.g.:
from:

Code: Select all

int var1, var2;
to:

Code: Select all

public int Getvar1()
{
    return this.var1;
}
public int Getvar2()
{
    return this.var2;
}
the problem is that the int is not constant, it could be any other type.
I tried with this:

Code: Select all

[\s]*([\w]+)(?:[ ]([\w]+),?)+;
This matches the string, but makes a replacement only for var2.

Re: Replace recursively

Posted: Sat Feb 02, 2008 1:00 pm
by Christopher
Maybe you could use __call() instead to implement your getters? I think there are examples in the manual.