Natural to String without space? (newbie question)
Author Message
Natural to String without space? (newbie question)

Natural'Image returns string with space at the begining. Is there any
standard way how to get number without this additional character?

Thanks,

Tomas

Sun, 09 Nov 2003 23:17:39 GMT
Natural to String without space? (newbie question)
I don't know if it's the easiest way, but there is a function in
trailing spaces.

For example:

Put( Trim( Natural'IMAGE( value ), both )  );

FYI: I recommend browsing through Appendix A of the Ada 95 reference manual.
This appendix has descriptions of the standard library included with Ada 95.

I hope this helps,
SteveD

Quote:
> Natural'Image returns string with space at the begining. Is there any
> standard way how to get number without this additional character?

> Thanks,

> Tomas

Mon, 10 Nov 2003 06:37:02 GMT
Natural to String without space? (newbie question)
Probably the best way is:

Make your own common function, such as:

function Trim(the_String : string) return string is
begin
return Trim(source => the_String,
side   => both);
end Trim;

Then include it in a context clause, such as:

with Trim;

procedure Trim_Test is

number : natural := 1234;

begin

end Trim_Test;

Hope this helps.
Frank

Quote:
-----Original Message-----

Sent: Wednesday, May 23, 2001 11:18 AM

Subject: Natural to String without space? (newbie question)

Natural'Image returns string with space at the begining. Is there any
standard way how to get number without this additional character?

Thanks,

Tomas
_______________________________________________

Mon, 10 Nov 2003 06:45:05 GMT
Natural to String without space? (newbie question)

Quote:

> Natural'Image returns string with space at the begining. Is there any
> standard way how to get number without this additional character?

Others have given solution using Trim. Another one is simply:

function Image (N : in Natural) return String is
N_Image : constant String := Natural'Image (N);
begin
return N_Image (2 .. N_Image'Last);
end Image;

--

--|------------------------------------------------------
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|
--| "The best way to travel is by means of imagination"

Mon, 10 Nov 2003 14:33:00 GMT
Natural to String without space? (newbie question)
or,

function Trim (Value : String;

Quote:
> Probably the best way is:

> Make your own common function, such as:

>    function Trim(the_String : string) return string is
>    begin
>       return Trim(source => the_String,
>                   side   => both);
>    end Trim;

> Then include it in a context clause, such as:

>    with Trim;

>    procedure Trim_Test is

>       number : natural := 1234;

>    begin

>    end Trim_Test;

> Hope this helps.
> Frank

> -----Original Message-----

> Sent: Wednesday, May 23, 2001 11:18 AM

> Subject: Natural to String without space? (newbie question)

> Natural'Image returns string with space at the begining. Is there any
> standard way how to get number without this additional character?

> Thanks,

> Tomas
> _______________________________________________

Mon, 10 Nov 2003 15:56:27 GMT
Natural to String without space? (newbie question)
Well, you learn something new everyday.  I didn't know you
could do a rename and default a parameter when the parent
function was not defaulted.

Thanks for the info.

Frank

Quote:
-----Original Message-----

or,

function Trim (Value : String;

> Probably the best way is:

> Make your own common function, such as:

>    function Trim(the_String : string) return string is
>    begin
>       return Trim(source => the_String,
>                   side   => both);
>    end Trim;

> Then include it in a context clause, such as:

>    with Trim;

>    procedure Trim_Test is

>       number : natural := 1234;

>    begin

>    end Trim_Test;

> Hope this helps.
> Frank

> -----Original Message-----

> Sent: Wednesday, May 23, 2001 11:18 AM

> Subject: Natural to String without space? (newbie question)

> Natural'Image returns string with space at the begining. Is there any
> standard way how to get number without this additional character?

> Thanks,

> Tomas
> _______________________________________________

_______________________________________________

Tue, 11 Nov 2003 05:55:23 GMT
Natural to String without space? (newbie question)
You're welcome, it's a nice little feature, isn't it? I
was wuick surprised myself the first time I saw it. :-)

Quote:
> Well, you learn something new everyday.  I didn't know you
> could do a rename and default a parameter when the parent
> function was not defaulted.

> Thanks for the info.

> Frank

> -----Original Message-----

> or,

>    function Trim (Value : String;

Tue, 11 Nov 2003 15:30:54 GMT
Natural to String without space? (newbie question)
Thanks.

Tomas

Tue, 11 Nov 2003 16:30:24 GMT
Natural to String without space? (newbie question)

Quote:
> You're welcome, it's a nice little feature, isn't it? I
> was wuick surprised myself the first time I saw it. :-)

But it seems you can't do this with generic parameters. Right?

--

http://purl.oclc.org/NET/ehudlamm <==  Me!

Tue, 11 Nov 2003 23:05:54 GMT
Natural to String without space? (newbie question)

You can even do the same when importing foreign functions, like :

with Interfaces.C_Streams; use Interfaces.C_Streams;

package Uio is

type Oflag_T is mod 2**32;
type Mode_T is mod 2**32;

<snip>

function Open(Path : chars; Oflag : Oflag_T; Mode : Mode_T := 8#777#) return int;

<snip>

pragma Import(C,open);
pragma Import(C,close);
pragma Import(C,fsync);
pragma Import(C,write);

end Uio;

Quote:
> You're welcome, it's a nice little feature, isn't it? I
> was wuick surprised myself the first time I saw it. :-)

> > Well, you learn something new everyday.  I didn't know you
> > could do a rename and default a parameter when the parent
> > function was not defaulted.

> > Thanks for the info.

> > Frank

> > -----Original Message-----

> > or,

> >    function Trim (Value : String;
> >       return String renames Ada.Strings.Fixed.Trim;

--
Kabelsalat ist gesund.

Ole-Hj. Kristensen

Wed, 12 Nov 2003 05:23:47 GMT
Natural to String without space? (newbie question)
that would seem to be the case given LM 8.5.5.
Quote:
> But it seems you can't do this with generic parameters. Right?

> --

> http://purl.oclc.org/NET/ehudlamm <==  Me!

Fri, 14 Nov 2003 15:31:46 GMT
Natural to String without space? (newbie question)

Quote:
> function Image (N : in Natural) return String is
>    N_Image : constant String := Natural'Image (N);
> begin
>    return N_Image (2 .. N_Image'Last);
> end Image;

Call me obsessive, but I feel safer with

function Image (N : in Natural) return String is
N_Image : constant String := Natural'Image (N);
begin
return N_Image (N'Image'First + 1 ..
N_Image'Last           );
end Image;

--
Wes Groleau
http://freepages.rootsweb.com/~wgroleau

Sun, 16 Nov 2003 05:04:13 GMT
Natural to String without space? (newbie question)

Quote:

> > function Image (N : in Natural) return String is
> >    N_Image : constant String := Natural'Image (N);
> > begin
> >    return N_Image (2 .. N_Image'Last);
> > end Image;

> Call me obsessive, but I feel safer with

>   function Image (N : in Natural) return String is
>      N_Image : constant String := Natural'Image (N);
>   begin
>      return N_Image (N'Image'First + 1 ..
>                      N_Image'Last           );
>   end Image;

OK: You're obsessive.

Actually, in the good old days (1984 or so) I used an Ada-83 compiler
that implemented 'Image with different 'First than 1, despite
ANSI/MIL-STD 1815A explicitly stating that it should be 1, so I tend to
use something more like the 2nd example than the first (except I would
use N_Image'First rather than N'Image'First).

--
Jeffrey Carter

Sun, 16 Nov 2003 07:00:57 GMT
Natural to String without space? (newbie question)

Quote:

> > function Image (N : in Natural) return String is
> >    N_Image : constant String := Natural'Image (N);
> > begin
> >    return N_Image (2 .. N_Image'Last);
> > end Image;

> Call me obsessive, but I feel safer with

Yes, since I think that N_Image will always start at 1 :)

But I tend to be obsessive in some case too so I understand your point :)

Pascal.

--

--|------------------------------------------------------
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------