digitalmars.D - converting c's c* to d strings
- llee (1/1) Jun 28 2008 Does anyone know how to convert from character array pointers in c to d ...
- Xinok (5/6) Jun 28 2008 You can convert any pointer type to an array type using slicing.
- torhu (6/14) Jun 28 2008 Or you can use std.string.toString(). It's cleaner, but slower because
- Jarrett Billingsley (4/16) Jun 28 2008 No is isn't, it does the exact same thing as what was posted above (cstr...
Does anyone know how to convert from character array pointers in c to d strings using Phobos?
Jun 28 2008
llee wrote:Does anyone know how to convert from character array pointers in c to d strings using Phobos?You can convert any pointer type to an array type using slicing. import std.c.string; char* cstr; string dstr = cstr[0..strlen(cstr)];
Jun 28 2008
Xinok wrote:llee wrote:Or you can use std.string.toString(). It's cleaner, but slower because it copies the string. To go the other way, use toStringz(). Or do dstr ~'\0'. D string literals always have a null terminator appended so you can use them directly with C functions.Does anyone know how to convert from character array pointers in c to d strings using Phobos?You can convert any pointer type to an array type using slicing. import std.c.string; char* cstr; string dstr = cstr[0..strlen(cstr)];
Jun 28 2008
"torhu" <no spam.invalid> wrote in message news:g46fa8$1hli$1 digitalmars.com...Xinok wrote:No is isn't, it does the exact same thing as what was posted above (cstr[0 .. strlen(cstr)]).llee wrote:Or you can use std.string.toString(). It's cleaner, but slower because it copies the string.Does anyone know how to convert from character array pointers in c to d strings using Phobos?You can convert any pointer type to an array type using slicing. import std.c.string; char* cstr; string dstr = cstr[0..strlen(cstr)];
Jun 28 2008
Jarrett Billingsley wrote:"torhu" <no spam.invalid> wrote in message news:g46fa8$1hli$1 digitalmars.com...Aaaaaaaargh! It's toStringz that copies the string. Can't remember the last time I was wrong about anything. :( In my defence, phobos 2.0 toString(char*) does actually copy...Xinok wrote:No is isn't, it does the exact same thing as what was posted above (cstr[0 ... strlen(cstr)]).llee wrote:Or you can use std.string.toString(). It's cleaner, but slower because it copies the string.Does anyone know how to convert from character array pointers in c to d strings using Phobos?You can convert any pointer type to an array type using slicing. import std.c.string; char* cstr; string dstr = cstr[0..strlen(cstr)];
Jun 28 2008
i just want to remember about unicode: when you pass D char[] to windows API *char you can use std.windows.charset.toMBSz() when you pass windows API *char to D char[] you can use std.windows.charset.fromMBSz()
Jun 28 2008