On Monday, 21 December 2015 at 05:39:32 UTC, Rikki Cattermole wrote:
size_t strLen = ...;
char* ptr = ...;

string myCString = cast(string)ptr[0 .. strLen];

I can't remember if it will include the null terminator or not, but if it does just decrease strLen by 1.

Strings from C libraries shouldn't be casted to immutable. If the characters of the C string are truly immutable, mark it as immutable(char)* in the binding (and needless to say, use fromStringz instead of explicit counting when the length isn't known).

Reply via email to