how to convert a c string to a d string?
问题 This is so simple I'm embarrassed to ask, but how do you convert a c string to a d string in D2? I've got two use cases. string convert( const(char)* c_str ); string convert( const(char)* c_str, size_t length ); 回答1: Use std.string.toString(char*) (D1/Phobos) or std.conv.to!(string) (D2): // D1 import std.string; ... string s = toString(c_str); // D2 import std.conv; ... string s = to!(string)(c_str); Slice the pointer: string s = c_str[0..len]; (you can't use "length" because it has a