[gtkada] Is there an sprintf style function in Ada?

Dmitry A. Kazakov mailbox at dmitry-kazakov.de
Tue Aug 29 11:20:51 CEST 2006


On Mon, 28 Aug 2006 20:27:47 -0400, you wrote:

> I want to be able to store a string that looks like this:
> 
> “#FFFFFF” but specify it with base 10 values.
> 
> Using sprintf and Perl I can do this:
> 
> sprintf("#%02x%02x%02x",255,255,255);
> 
> Is there an equivalent function in Ada that will do this?

with Strings_Edit

[http://www.dmitry-kazakov.de/ada/strings_edit.htm]

with Strings_Edit.Integers; use Strings_Edit.Integers;

function RGB_To_String (R, G, B : GUChar) return String is
   S : String (1..7);
   I : Integer := 2;
begin
   S (1) := '#';
   Put (S,I,(R*256+G)*256+B,Base=>16,Field=>6,Justify=>Right,Fill=>'0');
   return S;
end RGB_To_String;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



More information about the gtkada mailing list