On Wednesday, 15 January 2014 at 03:11:27 UTC, Adam D. Ruppe wrote:
On Wednesday, 15 January 2014 at 02:58:50 UTC, Sergey wrote:
And then back to void[] write to a file?

That's done automatically - any array will implicitly cast to const(void)[].

If you're writing a function that can take any kind of data, for example, std.file.write, it is nice to take a const void[] since then you can pass anything to it:

write("myfile", "a string"); // ok
write("myfile", [0, 1, 2,3]); // ok

and so on.


Going from void[] to any other array requires a cast, since it needs to know what kind of data you want to look at (void has no meaning itself, so indexing it would be nonsense), but going from something else to void happens implicitly.

So, please tell me how do I make replace:

//-------------
import std.stdio;
import std.file;
import std.array;


int main(){
        auto fl_txt = "E:/hosp/TMP/file.TXT";
        void[] str = std.file.read(fl_txt);
        ubyte[] pert = cast(ubyte[])str;        

        str2[0] = replace(pert, [9], [9,9,10]); // ?????????    

        std.file.write(fl_txt, pert);
        return 0;
}
//-------------

Reply via email to