string to char array?
Alex Parrill via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 2 09:26:29 PDT 2015
On Tuesday, 2 June 2015 at 16:23:26 UTC, Kyoji Klyden wrote:
> On Tuesday, 2 June 2015 at 15:53:33 UTC, Alex Parrill wrote:
>> On Tuesday, 2 June 2015 at 15:07:58 UTC, Kyoji Klyden wrote:
>>> quick question: What is the most efficient way to covert a
>>> string to a char array?
>>
>> A string is, by definition in D, a character array,
>> specifically `immutable(char)[]`. It's not like, for example,
>> Java in which it's a completely separate type; you can perform
>> all the standard array operations on strings.
>>
>> If you need to mutate a string, then you can create a mutable
>> `char[]` by doing `somestring.dup` as Dennis already mentioned.
>
> The problem I was having was actually that an opengl function
> (specifically glShaderSource) wouldn't accept strings. I'm
> still can't get it to work actually :P
>
> glShaderSource (uint, int, const(char*)*, const(int)*)
>
> This one function is a bugger, been going at this for hours.
>
>
> On Tuesday, 2 June 2015 at 15:38:24 UTC, Meta wrote:
>>
>> Note that this will allocate a new garbage collected array.
>
> Thx for the heads up
glShaderSource accepts an array of null-terminated strings. Try
this:
import std.string : toStringz;
string sources = source.toStringz;
int len = source.length;
glShaderSource(id, sources, 1, &sources, &len);
More information about the Digitalmars-d-learn
mailing list