digitalmars.D.learn - Integer to hexadecimal string
- jicman (10/10) Mar 11 2008 Greetings!
- BCS (3/32) Mar 11 2008 it under URI.
- jicman (2/38) Mar 12 2008 Thanks, but this does encodes but only does certain characters. No the ...
- jicman (5/24) Mar 11 2008 Maybe I am going at this the wrong way...
- novice2 (3/4) Mar 12 2008 imho, you should use std.windows.charset.toMBSz() while you pass string ...
- jicman (2/9) Mar 12 2008 Is this part of Phobos 1.0? I only see in in Phobos 2.0. Is there a sim...
- Dave Akers (11/21) Jul 08 2008 why not use format??
- BCS (13/43) Jul 08 2008 If you steal some code from Don Clugston:
- Jarrett Billingsley (7/10) Jul 08 2008 No function necessary.
- BCS (3/19) Jul 09 2008 I think that won't work. The only place I know that .stringof works that...
- Jarrett Billingsley (10/29) Jul 09 2008 Just try it, please?
- BCS (4/37) Jul 09 2008 I stand corrected:
Greetings! I know this has probably been asked before, or there is a simple way to do this, but I can not find it. I did a few searches on digitalmars on "decimal to hexadecimal" and got not hit. So, here is my problem: I am using a COM object that uses a file with filenames on it and everything works fine until I have accented characters on the filenames, such as é, Ñ, ä, etc. So, what I am trying to do is to change those filenames to URL style filename, such as, c:\temp\my file\josé.doc would change to, c:\temp\my%20file\jos%e9.doc So, I have two question: Is there a function in phobos that does this automatically? If not, how do I change an integer, say, 233 to hex, E9? I know how to do this programmatically, but there is gotta be an easier way then me writing a function for this. :-) thanks, josé
Mar 11 2008
Reply to jicman,Greetings! I know this has probably been asked before, or there is a simple way to do this, but I can not find it. I did a few searches on digitalmars on "decimal to hexadecimal" and got not hit. So, here is my problem: I am using a COM object that uses a file with filenames on it and everything works fine until I have accented characters on the filenames, such as é, Ñ, ä, etc. So, what I am trying to do is to change those filenames to URL style filename, such as, c:\temp\my file\josé.doc would change to, c:\temp\my%20file\jos%e9.doc So, I have two question: Is there a function in phobos that does this automatically? If not, how do I change an integer, say, 233 to hex, E9? I know how to do this programmatically, but there is gotta be an easier way then me writing a function for this. :-)it under URI. http://www.digitalmars.com/d/1.0/phobos/std_uri.htmlthanks, josé
Mar 11 2008
BCS Wrote:Reply to jicman,Thanks, but this does encodes but only does certain characters. No the ones I want like any accented or Spanish or, [any language, really,] characters. :-)Greetings! I know this has probably been asked before, or there is a simple way to do this, but I can not find it. I did a few searches on digitalmars on "decimal to hexadecimal" and got not hit. So, here is my problem: I am using a COM object that uses a file with filenames on it and everything works fine until I have accented characters on the filenames, such as é, Ñ, ä, etc. So, what I am trying to do is to change those filenames to URL style filename, such as, c:\temp\my file\josé.doc would change to, c:\temp\my%20file\jos%e9.doc So, I have two question: Is there a function in phobos that does this automatically? If not, how do I change an integer, say, 233 to hex, E9? I know how to do this programmatically, but there is gotta be an easier way then me writing a function for this. :-)it under URI. http://www.digitalmars.com/d/1.0/phobos/std_uri.htmlthanks, josé
Mar 12 2008
jicman Wrote:Greetings! I know this has probably been asked before, or there is a simple way to do this, but I can not find it. I did a few searches on digitalmars on "decimal to hexadecimal" and got not hit. So, here is my problem: I am using a COM object that uses a file with filenames on it and everything works fine until I have accented characters on the filenames, such as é, Ñ, ä, etc. So, what I am trying to do is to change those filenames to URL style filename, such as, c:\temp\my file\josé.doc would change to, c:\temp\my%20file\jos%e9.doc So, I have two question: Is there a function in phobos that does this automatically? If not, how do I change an integer, say, 233 to hex, E9? I know how to do this programmatically, but there is gotta be an easier way then me writing a function for this. :-) thanks, joséMaybe I am going at this the wrong way... Let me explain what the problem is: I am using D to call a software that uses a Windows COM object to process a file which refers to a bunch of other files. This file which this COM object uses as input I create using D. This file is created by my doing a std.file.listdir(fd,"*") and then using those items returned from the listdir. This works perfectly and I can create the file to pass to the COM object which uses the file paths referred in the created file and everything works. However, when I have files with accented characters, I no longer have this working. The COM application fails with "It can not find the path given..." and it gives the path, which interestingly enough, is broken exactly where the accented or extended character is. I know what the problem is UTF8 vs. ANSI or one of those file kinds. If I open the file I create, I can see the problem. It is changing the file I created to ANSI, when it is really UTF8. This COM object, since it is Windows (.NET to be exact) does not allow me to set the input file, so it wants something else than UTF8, which is what I am creating with D. So, before I go and try to go through each of those filenames and rename then using URL base strings, is there something else that I can do to make this file be anything other than UTF8? Thanks for the help. Just point me to where to start reading... josé
Mar 11 2008
jicman Wrote:other files. This file which this COM object uses as input I create using D. >This file is created by my doing a std.file.listdir(fd,"*") and then usingimho, you should use std.windows.charset.toMBSz() while you pass string from D to Windows API, and std.windows.charset.fromMBSz() while you pass string back from Windows API to D
Mar 12 2008
novice2 Wrote:jicman Wrote:Is this part of Phobos 1.0? I only see in in Phobos 2.0. Is there a similar call within Phobos 1.0?other files. This file which this COM object uses as input I create using D. This file is created by my doing a std.file.listdir(fd,"*") and then usingimho, you should use std.windows.charset.toMBSz() while you pass string from D to Windows API, and std.windows.charset.fromMBSz() while you pass string back from Windows API to D
Mar 12 2008
jicman wrote:novice2 Wrote:why not use format?? char[] hex = format("%.8x", 12345); that produces hex.. import std.string; char[] toHex(T)(T arg){ return format("%."~std.string.toString(T.sizeof * 2)~"x", arg); } i haven't tested that code. but i think it'd work for ulong long uint int ubyte and byte. -davejicman Wrote:Is this part of Phobos 1.0? I only see in in Phobos 2.0. Is there a similar call within Phobos 1.0?other files. This file which this COM object uses as input I create using D. This file is created by my doing a std.file.listdir(fd,"*") and then usingimho, you should use std.windows.charset.toMBSz() while you pass string from D to Windows API, and std.windows.charset.fromMBSz() while you pass string back from Windows API to D
Jul 08 2008
Reply to Dave,jicman wrote:If you steal some code from Don Clugston: http://www.dsource.org/projects/ddl/browser/trunk/meta/conv.d template decimaldigit(int n) { const char [] decimaldigit = "0123456789"[n..n+1]; } template itoa(long n) { static if (n<0) const char [] itoa = "-" ~ itoa!(-n); else static if (n<10L) const char [] itoa = decimaldigit!(n); else const char [] itoa = itoa!(n/10L) ~ decimaldigit!(n%10L); } you can even force the format string to be built at compile time. char[] toHex(T)(T arg){ return format("%."~itoa!(T.sizeof * 2)~"x", arg); }novice2 Wrote:why not use format?? char[] hex = format("%.8x", 12345); that produces hex.. import std.string; char[] toHex(T)(T arg){ return format("%."~std.string.toString(T.sizeof * 2)~"x", arg); } i haven't tested that code. but i think it'd work for ulong long uint int ubyte and byte. -davejicman Wrote:Is this part of Phobos 1.0? I only see in in Phobos 2.0. Is there a similar call within Phobos 1.0?other files. This file which this COM object uses as input I create using D. This file is created by my doing a std.file.listdir(fd,"*") and then usingimho, you should use std.windows.charset.toMBSz() while you pass string from D to Windows API, and std.windows.charset.fromMBSz() while you pass string back from Windows API to D
Jul 08 2008
"BCS" <ao pathlink.com> wrote in message news:55391cb32eed78caaf3194222520 news.digitalmars.com...you can even force the format string to be built at compile time. char[] toHex(T)(T arg){ return format("%."~itoa!(T.sizeof * 2)~"x", arg); }No function necessary. return format("%." ~ (T.sizeof * 2).stringof ~ "x", arg); Untested, but you can use .stringof to do number to string at compile time. Not sure if it'll give "T.sizeof * 2" instead here :P might have to put it in a const.
Jul 08 2008
Reply to Jarrett,"BCS" <ao pathlink.com> wrote in message news:55391cb32eed78caaf3194222520 news.digitalmars.com...I think that won't work. The only place I know that .stringof works that way is __LINE__.stringof but that's special cased in the lexer IIRC.you can even force the format string to be built at compile time. char[] toHex(T)(T arg){ return format("%."~itoa!(T.sizeof * 2)~"x", arg); }No function necessary. return format("%." ~ (T.sizeof * 2).stringof ~ "x", arg); Untested, but you can use .stringof to do number to string at compile time. Not sure if it'll give "T.sizeof * 2" instead here :P might have to put it in a const.
Jul 09 2008
"BCS" <ao pathlink.com> wrote in message news:55391cb32ef558caafbcbd0e7af2 news.digitalmars.com...Reply to Jarrett,Just try it, please? template Itoa(int x) { const Itoa = x.stringof; } pragma(msg, (5).stringof); // "5" pragma(msg, (3 + 4).stringof); // "3 + 4" pragma(msg, Itoa!(3 + 4)); // "7""BCS" <ao pathlink.com> wrote in message news:55391cb32eed78caaf3194222520 news.digitalmars.com...I think that won't work. The only place I know that .stringof works that way is __LINE__.stringof but that's special cased in the lexer IIRC.you can even force the format string to be built at compile time. char[] toHex(T)(T arg){ return format("%."~itoa!(T.sizeof * 2)~"x", arg); }No function necessary. return format("%." ~ (T.sizeof * 2).stringof ~ "x", arg); Untested, but you can use .stringof to do number to string at compile time. Not sure if it'll give "T.sizeof * 2" instead here :P might have to put it in a const.
Jul 09 2008
Reply to Jarrett,"BCS" <ao pathlink.com> wrote in message news:55391cb32ef558caafbcbd0e7af2 news.digitalmars.com...I stand corrected: It didn't work last time I tried it. (I think I only managed to test case 2 & 1but with consts)Reply to Jarrett,Just try it, please? template Itoa(int x) { const Itoa = x.stringof; } pragma(msg, (5).stringof); // "5" pragma(msg, (3 + 4).stringof); // "3 + 4" pragma(msg, Itoa!(3 + 4)); // "7""BCS" <ao pathlink.com> wrote in message news:55391cb32eed78caaf3194222520 news.digitalmars.com...I think that won't work. The only place I know that .stringof works that way is __LINE__.stringof but that's special cased in the lexer IIRC.you can even force the format string to be built at compile time. char[] toHex(T)(T arg){ return format("%."~itoa!(T.sizeof * 2)~"x", arg); }No function necessary. return format("%." ~ (T.sizeof * 2).stringof ~ "x", arg); Untested, but you can use .stringof to do number to string at compile time. Not sure if it'll give "T.sizeof * 2" instead here :P might have to put it in a const.
Jul 09 2008