std.regex.replace issues

Jesse Phillips jessekphillips+D at gmail.com
Thu Mar 17 12:38:29 PDT 2011


Andrej Mitrovic Wrote:

>     char[] replacement;
>     foreach (char[] line; file.byLine())
>     {
>         replacement = line.replace(regex("->"), ".")
>                                   .replace(regex("::"), ".")
>                                   .replace(regex("//.*"), "")
>                                   .replace(regex("\\*"), "");
>        // do something with replacement while its still alive..
>     }
> 
> How would I go about achieving this?
> And if I use strings instead isn't this going to involve a lot of duplication?

Replace should probably work with char[], but not for efficiency. Unless I am wrong you will still cause a large amount of copying when replacing a single/multiple string with a multiple/single string. You may avoid re-allocation, but even that isn't guarantied.


More information about the Digitalmars-d-learn mailing list