Thank you, core.runtime.Runtime.initialize() fixed the issue. I
am now able to use to!string as well. I found your posts and Ali
Çehreli's posts on this subject. I think I have some
understanding now.
On Saturday, 9 December 2017 at 06:14:36 UTC, Venkat wrote:
Thanks for the quick response. std.string.fromStringz did the
trick. I am not sure what was the deal with to!string.
Be careful with fromStringz. It doesn't allocate a new string, so
the returned string can easily become corrupted if
Thanks for the quick response. std.string.fromStringz did the
trick. I am not sure what was the deal with to!string.
On Saturday, 9 December 2017 at 05:55:21 UTC, Venkat wrote:
I am trying out the DJni library
(https://github.com/Monnoroch/DJni). For some reason
std.conv.to!string doesn't want to convert a char* to a
string.The lines below are taken from the log. I see that the
last frame is at gc_qalloc. I
I am trying out the DJni library
(https://github.com/Monnoroch/DJni). For some reason
std.conv.to!string doesn't want to convert a char* to a
string.The lines below are taken from the log. I see that the
last frame is at gc_qalloc. I am not sure why it failed there.
Can anybody elaborate on wh
g-Language/phobos/pull/3528
>>>
>>> However the auto builder fails, with the error message:
>>>> runnable/test23.d(1219): Error: cannot implicitly convert expression
>>>> (format("s = %s", s)) of type char[] to string
>>>
>>> The line whic
implicitly convert expression
(format("s = %s", s)) of type char[] to string
The line which fails is `p = std.string.format("s = %s", s);`
I don't understand why I can't convert a char[] to string.
Get rid of the 'in' in format's signature.
Oh,
uot;s = %s", s)) of type char[] to string
The line which fails is `p = std.string.format("s = %s", s);`
I don't understand why I can't convert a char[] to string.
Get rid of the 'in' in format's signature.
:
runnable/test23.d(1219): Error: cannot implicitly convert
expression (format("s = %s", s)) of type char[] to string
The line which fails is `p = std.string.format("s = %s", s);`
I don't understand why I can't convert a char[] to string.
I think it has to do with th
expression (format("s = %s", s)) of type char[] to string
The line which fails is `p = std.string.format("s = %s", s);`
I don't understand why I can't convert a char[] to string.
I think it has to do with the fact that string is an alias to
immutable(char)[]
I made a PR to phobos where I modified `std.format.format`.
https://github.com/D-Programming-Language/phobos/pull/3528
However the auto builder fails, with the error message:
runnable/test23.d(1219): Error: cannot implicitly convert
expression (format("s = %s", s)) of type char[]
On Tue, 25 Mar 2014 19:13:07 -0400, H. S. Teoh
wrote:
On Tue, Mar 25, 2014 at 10:02:33PM +, monarch_dodra wrote:
On Tuesday, 25 March 2014 at 21:35:47 UTC, Mark Isaacson wrote:
>Is there a performance benefit? Is it simply because it's more general?
[...]
There is *1* thing you should
On Tue, Mar 25, 2014 at 10:02:33PM +, monarch_dodra wrote:
> On Tuesday, 25 March 2014 at 21:35:47 UTC, Mark Isaacson wrote:
> >Is there a performance benefit? Is it simply because it's more general?
[...]
> There is *1* thing you should take into account though: "to!" is a
> no-op for string=>
Much appreciated everyone! I had a vague intuition that these
were the reasons, but it was helpful to spell them out. I'm
especially partial to the self-documentation reasoning.
On Tuesday, 25 March 2014 at 21:35:47 UTC, Mark Isaacson wrote:
Is there a performance benefit? Is it simply because it's more
general?
Mostly because it's more generic. For example:
If instead you want to do "string" => "char[]", then your code
will have to be changed to use "dup".
if instead
Mark Isaacson:
why use `to!string` instead of just doing `line[2 .. $].idup`?
I sometimes prefer the text function:
= line[2 .. $].text;
Bye,
bearophile
On Tue, 25 Mar 2014 21:35:46 +, Mark Isaacson wrote:
> I am presently working my way through TDPL for the second time, and
> there's an example in chapter 1 to the effect of:
>
> [code]
> string currentParagraph;
> foreach(line; stdin.byLine()) {
>if (line.length > 2) {
> currentPara
I am presently working my way through TDPL for the second time,
and there's an example in chapter 1 to the effect of:
[code]
string currentParagraph;
foreach(line; stdin.byLine()) {
if (line.length > 2) {
currentParagraph = to!string(line[2 .. $]);
}
}
[/code]
The explicit conversion
Gary Willoughby:
I've noticed that const(char)** can be accessed via indexes:
writefln("%s", pp[0].to!(string)); //etc.
cool!
This is a feature that works with all pointers to a sequence of
items, like in C. But array bounds are not verified, so it's more
bug-prone. So if you know the leng
i'll answer in code
http://dpaste.dzfl.pl/2bb1a1a8
On Thursday, 2 January 2014 at 15:31:25 UTC, bearophile wrote:
Gary Willoughby:
Another question: how do i convert const(char)** to string[]?
If you know that you have N strings, then a solution is
(untested):
pp[0 .. N].map!text.array
If it doesn't work, try:
pp[0 .. N].map!(to!s
On Thursday, 2 January 2014 at 15:53:40 UTC, Adam D. Ruppe wrote:
On Thursday, 2 January 2014 at 15:31:25 UTC, bearophile wrote:
If you know that you have N strings, then a solution is
(untested):
Or if it is zero terminated, maybe
pp.until!"a is null".map!text.array
Though personally I'd j
On Thursday, 2 January 2014 at 15:31:25 UTC, bearophile wrote:
If you know that you have N strings, then a solution is
(untested):
Or if it is zero terminated, maybe
pp.until!"a is null".map!text.array
Though personally I'd just use the plain old for loop.
You are going to need the length of your c char*[] then a
for-loop should do it :D
Gary Willoughby:
Another question: how do i convert const(char)** to string[]?
If you know that you have N strings, then a solution is
(untested):
pp[0 .. N].map!text.array
If it doesn't work, try:
pp[0 .. N].map!(to!string).array
Bye,
bearophile
you can then do
string r = to!string(result);
or
char[] r = result[0 .. strlen(result)];
and use that/
Another question: how do i convert const(char)** to string[]?
On Wednesday, 1 January 2014 at 23:09:05 UTC, Adam D. Ruppe wrote:
On Wednesday, 1 January 2014 at 23:03:06 UTC, Gary Willoughby
wrote:
I'm calling an external C function which returns a string
delivered via a char*. When i print this string out, like this:
char* result = func();'
you can th
On Wednesday, 1 January 2014 at 23:03:06 UTC, Gary Willoughby
wrote:
I'm calling an external C function which returns a string
delivered via a char*. When i print this string out, like this:
char* result = func();
writefln("String: %s", *result);
I only get one character printed.
You're not
On Wednesday, 1 January 2014 at 23:03:06 UTC, Gary Willoughby
wrote:
I'm calling an external C function which returns a string
delivered via a char*. When i print this string out, like this:
char* result = func();'
you can then do
string r = to!string(result);
or
char[] r = result[0 .. str
I'm calling an external C function which returns a string
delivered via a char*. When i print this string out, like this:
char* result = func();
writefln("String: %s", *result);
I only get one character printed. I guess this is expected
because i'm only returned a pointer to the first char. I
convert expression
> > (get(cast(const(char)[])address, AutoProtocol())) of type
> > char[] to string
> >
> > string address = "http://dlang.org";;
> > string _data = get(address);
>
> You have two options:
>
> string address = "http://dlang.
)) of type char[] to string
string address = "http://dlang.org";;
string _data = get(address);
`get` returns mutable data, one should respect it:
char[] data = get(address); // or just use `auto data = `
However, that data can automatically be converted to string if get()
we
On Thursday, 14 November 2013 at 19:41:13 UTC, Agustin wrote:
I'm trying to use http://dlang.org/phobos/std_net_curl.html and
when i compile the same example i get:
cannot implicitly convert expression
(get(cast(const(char)[])address, AutoProtocol())) of type
char[] to string
s
On Thursday, 14 November 2013 at 19:41:13 UTC, Agustin wrote:
I'm trying to use http://dlang.org/phobos/std_net_curl.html and
when i compile the same example i get:
cannot implicitly convert expression
(get(cast(const(char)[])address, AutoProtocol())) of type
char[] to string
s
I'm trying to use http://dlang.org/phobos/std_net_curl.html and
when i compile the same example i get:
cannot implicitly convert expression
(get(cast(const(char)[])address, AutoProtocol())) of type char[]
to string
string address = "http://dlang.org";;
string _data = get(address);
Chopin:
Is this the fastest way to append a char to string?
char c = 'a';
string s;
s ~= c;
?
I have a program that does this many many times... and it's
slow. So I was wondering it it could be it.
Try the appender from std.array. It's supposed to be faster, but
somet
On Tuesday, 11 December 2012 at 15:52:31 UTC, Chopin wrote:
Is this the fastest way to append a char to string?
char c = 'a';
string s;
s ~= c;
?
I have a program that does this many many times... and it's
slow. So I was wondering it it could be it.
Thanks for tips!
This
Is this the fastest way to append a char to string?
char c = 'a';
string s;
s ~= c;
?
I have a program that does this many many times... and it's slow.
So I was wondering it it could be it.
Thanks for tips!
Jonathan M Davis:
> it's generally best to use dup and idup only when you
> definitely want to make a copy. By using them, you're explicitly stating that
> you _want_ a copy to be made. If you just want a conversion, then to!() will
> do the trick in what is hopefully the most efficient way pos
On 2011-06-10 19:56, Jonathan Sternberg wrote:
> Why doesn't this work?
>
> import std.stdio;
>
> string copy_string(char [] input)
> {
> return input.dup;
> }
>
> int main()
> {
> char [] buf = ['h', 'e', 'l', 'l', 'o'];
> writeln( copy_string(buf) );
> }
>
> I want to do something mor
On 2011-06-11 05:12, bearophile wrote:
> Jonathan M Davis:
> > Even better though, would be to use std.conv.to - e.g. to!string(input).
> > This will convert input to a string, but it has the advantage that if
> > input is already a string, then it'll just return the string rather than
> > making a
Jonathan M Davis:
> Even better though, would be to use std.conv.to - e.g. to!string(input). This
> will
> convert input to a string, but it has the advantage that if input is already
> a
> string, then it'll just return the string rather than making another copy
> like
> idup would.
I didn
On 2011-06-10 19:56, Jonathan Sternberg wrote:
> Why doesn't this work?
>
> import std.stdio;
>
> string copy_string(char [] input)
> {
> return input.dup;
> }
>
> int main()
> {
> char [] buf = ['h', 'e', 'l', 'l', 'o'];
> writeln( copy_string(buf) );
> }
>
> I want to do something
Why doesn't this work?
import std.stdio;
string copy_string(char [] input)
{
return input.dup;
}
int main()
{
char [] buf = ['h', 'e', 'l', 'l', 'o'];
writeln( copy_string(buf) );
}
I want to do something more complex. In my code, I want to have a dynamic
array that I can append stu
On 05/11/2009 00:11, BLS wrote:
char* xxx()
better
char* xxx(char* a, char* b)
{
string A =
}
HI,
I would like to use some pbobos string based functions within an DLL.
Unfortunately all I can do is to pass char* parameters from the callee
side.
Now I want to use f.i. std.regex
export extern(windows) char* xxx()
//Heck were is Jarret when I need him most ?
D2,beside
Björn
46 matches
Mail list logo