Re: std.conv.to!string refuses to convert a char* to string.

2017-12-09 Thread Venkat via Digitalmars-d-learn
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.

Re: std.conv.to!string refuses to convert a char* to string.

2017-12-09 Thread Mike Parker via Digitalmars-d-learn
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

Re: std.conv.to!string refuses to convert a char* to string.

2017-12-08 Thread Venkat via Digitalmars-d-learn
Thanks for the quick response. std.string.fromStringz did the trick. I am not sure what was the deal with to!string.

Re: std.conv.to!string refuses to convert a char* to string.

2017-12-08 Thread Neia Neutuladh via Digitalmars-d-learn
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

std.conv.to!string refuses to convert a char* to string.

2017-12-08 Thread Venkat via Digitalmars-d-learn
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

Re: cannot implicitly convert char[] to string

2015-08-15 Thread Ali Çehreli via Digitalmars-d-learn
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

Re: cannot implicitly convert char[] to string

2015-08-15 Thread Timon Gehr via Digitalmars-d-learn
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,

Re: cannot implicitly convert char[] to string

2015-08-15 Thread Timon Gehr via Digitalmars-d-learn
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.

Re: cannot implicitly convert char[] to string

2015-08-15 Thread cym13 via Digitalmars-d-learn
: 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

Re: cannot implicitly convert char[] to string

2015-08-15 Thread cym13 via Digitalmars-d-learn
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)[]

cannot implicitly convert char[] to string

2015-08-15 Thread vladde via Digitalmars-d-learn
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[]

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Steven Schveighoffer
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

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread H. S. Teoh
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=>

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Mark Isaacson
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.

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread monarch_dodra
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

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread bearophile
Mark Isaacson: why use `to!string` instead of just doing `line[2 .. $].idup`? I sometimes prefer the text function: = line[2 .. $].text; Bye, bearophile

Re: [Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Justin Whear
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

[Style] Converting from char[] to string, to!string vs idup

2014-03-25 Thread Mark Isaacson
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

Re: How to handle char* to string from C functions?

2014-01-02 Thread bearophile
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

Re: How to handle char* to string from C functions?

2014-01-02 Thread uc
i'll answer in code http://dpaste.dzfl.pl/2bb1a1a8

Re: How to handle char* to string from C functions?

2014-01-02 Thread Gary Willoughby
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

Re: How to handle char* to string from C functions?

2014-01-02 Thread monarch_dodra
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

Re: How to handle char* to string from C functions?

2014-01-02 Thread Adam D. Ruppe
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.

Re: How to handle char* to string from C functions?

2014-01-02 Thread uc
You are going to need the length of your c char*[] then a for-loop should do it :D

Re: How to handle char* to string from C functions?

2014-01-02 Thread bearophile
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

Re: How to handle char* to string from C functions?

2014-01-02 Thread Gary Willoughby
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[]?

Re: How to handle char* to string from C functions?

2014-01-02 Thread Gary Willoughby
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

Re: How to handle char* to string from C functions?

2014-01-01 Thread John Colvin
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

Re: How to handle char* to string from C functions?

2014-01-01 Thread Adam D. Ruppe
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

How to handle char* to string from C functions?

2014-01-01 Thread Gary Willoughby
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

Re: Cannot cast char[] to string.

2013-11-14 Thread Jonathan M Davis
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.

Re: Cannot cast char[] to string.

2013-11-14 Thread Ali Çehreli
)) 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

Re: Cannot cast char[] to string.

2013-11-14 Thread Brad Anderson
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

Re: Cannot cast char[] to string.

2013-11-14 Thread Dicebot
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

Cannot cast char[] to string.

2013-11-14 Thread Agustin
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);

Re: Fastest way to append char to string?

2012-12-11 Thread bearophile
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

Re: Fastest way to append char to string?

2012-12-11 Thread monarch_dodra
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

Fastest way to append char to string?

2012-12-11 Thread 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. Thanks for tips!

Re: char[] to string

2011-06-11 Thread bearophile
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

Re: char[] to string

2011-06-11 Thread Timon Gehr
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

Re: char[] to string

2011-06-11 Thread Jonathan M Davis
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

Re: char[] to string

2011-06-11 Thread bearophile
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

Re: char[] to string

2011-06-10 Thread Jonathan M Davis
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

char[] to string

2011-06-10 Thread Jonathan Sternberg
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

Re: char* to string

2009-11-04 Thread BLS
On 05/11/2009 00:11, BLS wrote: char* xxx() better char* xxx(char* a, char* b) { string A = }

char* to string

2009-11-04 Thread BLS
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