www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - hex strings

reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
just out of curiosity, does anyone use these and actually mean them to 
be strings? It seems like I'm invariably writing

cast(ubyte[]) x"..."
Jan 26 2011
next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Wednesday, January 26, 2011 10:25:29 Ellery Newcomer wrote:
 just out of curiosity, does anyone use these and actually mean them to
 be strings? It seems like I'm invariably writing
 
 cast(ubyte[]) x"..."

That's legal? I thought that x went in front of hex literals, not strings. I wouldn't have thought that that code would compile, and I certainly have no clue what you're trying to do. So, I certainly don't fall in the category of anyone using it - regardless of whether it's meant to be a string or not. - Jonathan M Davis
Jan 26 2011
parent reply bearophile <bearophileHUGS lycos.com> writes:
Jonathan M Davis:

 That's legal?

They are a part of D language, search for "Hex Strings" here: http://www.digitalmars.com/d/2.0/lex.html Bye, bearophile
Jan 26 2011
parent Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On 01/26/2011 01:35 PM, Jonathan M Davis wrote:
 On Wednesday, January 26, 2011 11:29:59 bearophile wrote:
 Jonathan M Davis:
 That's legal?

They are a part of D language, search for "Hex Strings" here: http://www.digitalmars.com/d/2.0/lex.html

It always seems like there's at least one more thing in the language that I have no idea is there... - Jonathan M Davis

helps to have written a D lexer or two. weren't you going to do that?
Jan 26 2011
prev sibling next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Wednesday, January 26, 2011 11:29:59 bearophile wrote:
 Jonathan M Davis:
 That's legal?

They are a part of D language, search for "Hex Strings" here: http://www.digitalmars.com/d/2.0/lex.html

It always seems like there's at least one more thing in the language that I have no idea is there... - Jonathan M Davis
Jan 26 2011
prev sibling next sibling parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:

 just out of curiosity, does anyone use these and actually mean them to  
 be strings? It seems like I'm invariably writing

 cast(ubyte[]) x"..."

Never used them, tbh. But shouldn't that be cast(ubyte[]) x"...".dup ? -- Simen
Jan 26 2011
next sibling parent Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On 01/26/2011 02:16 PM, Simen kjaeraas wrote:
 Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:

 just out of curiosity, does anyone use these and actually mean them to
 be strings? It seems like I'm invariably writing

 cast(ubyte[]) x"..."

Never used them, tbh. But shouldn't that be cast(ubyte[]) x"...".dup ?

yeah, strictly speaking. but that (or cast(immutable(ubyte[]))) would be even uglier.
Jan 26 2011
prev sibling parent bearophile <bearophileHUGS lycos.com> writes:
Simen kjaeraas:

 cast(ubyte[]) x"..."

Never used them, tbh. But shouldn't that be cast(ubyte[]) x"...".dup

Maybe it's to avoid such mistakes that C++ has const_cast separated from other casts. Bye, bearophile
Jan 26 2011
prev sibling next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Wednesday 26 January 2011 11:53:32 Ellery Newcomer wrote:
 On 01/26/2011 01:35 PM, Jonathan M Davis wrote:
 On Wednesday, January 26, 2011 11:29:59 bearophile wrote:
 Jonathan M Davis:
 That's legal?

They are a part of D language, search for "Hex Strings" here: http://www.digitalmars.com/d/2.0/lex.html

It always seems like there's at least one more thing in the language that I have no idea is there... - Jonathan M Davis

helps to have written a D lexer or two. weren't you going to do that?

I've been working on it off and on, but I've been busy enough that I haven't made as much progress on it as I'd like. Even so though, I might have already run into it there and totally forgot about it, because it's a feature that I've never used and have no use for. - Jonathan M Davis
Jan 26 2011
prev sibling next sibling parent reply spir <denis.spir gmail.com> writes:
On 01/26/2011 07:25 PM, Ellery Newcomer wrote:
 just out of curiosity, does anyone use these and actually mean them to be
 strings? It seems like I'm invariably writing

 cast(ubyte[]) x"..."

Super-nice for universal text. Anything you can't type in because of non-illimited keyboard size... Actually had a similar idea, except using in-string delimiters #...# instead of a prefix: "#xx xxx xxxx xxx#" Adds one char compared to D syntax, but allows partially hex-coded string: "blah #xx xxxx xxx# blah" Denis -- _________________ vita es estrany spir.wikidot.com
Jan 26 2011
parent Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On 01/26/2011 05:57 PM, spir wrote:
 On 01/26/2011 07:25 PM, Ellery Newcomer wrote:
 just out of curiosity, does anyone use these and actually mean them to be
 strings? It seems like I'm invariably writing

 cast(ubyte[]) x"..."

Super-nice for universal text. Anything you can't type in because of non-illimited keyboard size... Actually had a similar idea, except using in-string delimiters #...# instead of a prefix: "#xx xxx xxxx xxx#" Adds one char compared to D syntax, but allows partially hex-coded string: "blah #xx xxxx xxx# blah" Denis

personally, I always use \uxxxx or \Uxxxxxxxx [and then print it out to the console, copy it, and paste it back into my code]
Jan 26 2011
prev sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
spir <denis.spir gmail.com> wrote:

 Adds one char compared to D syntax, but allows partially hex-coded  
 string:
 	"blah #xx xxxx xxx# blah"

I like having the ability to embed #'s in my strings, thank you. -- Simen
Jan 26 2011