std.regex.replace issues
Andrej Mitrovic
none at none.none
Thu Mar 17 10:54:47 PDT 2011
I've tried using this:
auto file = File("file.cpp", "r");
char[] replacement;
foreach (char[] line; file.byLine())
{
replacement = line.replace(regex("//.*"), ".");
// do something with replacement while its still alive..
}
This gives me this bombshell of an error:
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\regex.d(2666): Error: cannot implicitly convert expression (result) of type string to char[]
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\regex.d(2571): Error: template instance std.regex.RegexMatch!(char[]).RegexMatch.replace3!(string) error instantiating
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\regex.d(1838): instantiated from here: replace!(string)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\regex.d(2854): instantiated from here: replaceAll!(string)
qttod.d(15): instantiated from here: replace!(char[],Regex!(char),string)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\regex.d(1838): Error: template instance std.regex.RegexMatch!(char[]).RegexMatch.replace!(string) error instantiating
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\regex.d(2854): instantiated from here: replaceAll!(string)
qttod.d(15): instantiated from here: replace!(char[],Regex!(char),string)
>Exit code: 1
I want to compose with `replace`. So I figured using char[]'s would avoid duplication. I want to use code like this:
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?
More information about the Digitalmars-d-learn
mailing list