5

我有定义为指针+大小的字节数组:

  size_t size;   // size in bytes
  void   *data;  // NOT zero-terminated string

如何从中构造(最好是零拷贝)“字符串”?

4

1 回答 1

7

这假设data指向不可变内存:

string s = (cast(immutable(char)*)data)[0..size];

如果不是,则 achar[]会比字符串更合适,或者您可以使用.idup.

于 2015-02-17T00:57:15.263 回答