comp.lang.ada
 help / color / mirror / Atom feed
* Natural to String without space? (newbie question)
@ 2001-05-23 15:17 Tomas Hlavaty
  2001-05-23 22:37 ` DuckE
  2001-05-24  6:33 ` Pascal Obry
  0 siblings, 2 replies; 14+ messages in thread
From: Tomas Hlavaty @ 2001-05-23 15:17 UTC (permalink / raw)


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

Thanks,

Tomas



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Natural to String without space? (newbie question)
  2001-05-23 15:17 Natural to String without space? (newbie question) Tomas Hlavaty
@ 2001-05-23 22:37 ` DuckE
  2001-05-24  6:33 ` Pascal Obry
  1 sibling, 0 replies; 14+ messages in thread
From: DuckE @ 2001-05-23 22:37 UTC (permalink / raw)


I don't know if it's the easiest way, but there is a function in
Ada.Strings.Fixed called "Trim" that may be used to eliminate leading and
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


"Tomas Hlavaty" <hlavaty@labe.felk.cvut.cz> wrote in message
news:3B0BD493.5ABBA12B@labe.felk.cvut.cz...
> Natural'Image returns string with space at the begining. Is there any
> standard way how to get number without this additional character?
>
> Thanks,
>
> Tomas





^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Natural to String without space? (newbie question)
@ 2001-05-23 22:45 Beard, Frank
  2001-05-24  7:56 ` Martin Dowie
  0 siblings, 1 reply; 14+ messages in thread
From: Beard, Frank @ 2001-05-23 22:45 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

Probably the best way is:

Make your own common function, such as:

   with Ada.Strings;        use Ada.Srings;
   with Ada.Strings.Fixed;  use Ada.Srings.Fixed;

   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 Ada.Text_Io;
   with Trim;

   procedure Trim_Test is

      number : natural := 1234;

   begin

      Ada.Text_Io.Put_Line(Trim(natural'image(number)));

   end Trim_Test;


Hope this helps.
Frank

-----Original Message-----
From: Tomas Hlavaty [mailto:hlavaty@labe.felk.cvut.cz]
Sent: Wednesday, May 23, 2001 11:18 AM
To: comp.lang.ada@ada.eu.org
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
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Natural to String without space? (newbie question)
  2001-05-23 15:17 Natural to String without space? (newbie question) Tomas Hlavaty
  2001-05-23 22:37 ` DuckE
@ 2001-05-24  6:33 ` Pascal Obry
  2001-05-29 21:04   ` Wes Groleau
  1 sibling, 1 reply; 14+ messages in thread
From: Pascal Obry @ 2001-05-24  6:33 UTC (permalink / raw)



Tomas Hlavaty <hlavaty@labe.felk.cvut.cz> writes:

> 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;

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Natural to String without space? (newbie question)
  2001-05-23 22:45 Beard, Frank
@ 2001-05-24  7:56 ` Martin Dowie
  0 siblings, 0 replies; 14+ messages in thread
From: Martin Dowie @ 2001-05-24  7:56 UTC (permalink / raw)


or,

   function Trim (Value : String;
                  Side  : Ada.Strings.Trim_End := Ada.Strings.Both)
      return String renames Ada.Strings.Fixed.Trim;


Beard, Frank <beardf@spawar.navy.mil> wrote in message
news:mailman.990658037.12046.comp.lang.ada@ada.eu.org...
> Probably the best way is:
>
> Make your own common function, such as:
>
>    with Ada.Strings;        use Ada.Srings;
>    with Ada.Strings.Fixed;  use Ada.Srings.Fixed;
>
>    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 Ada.Text_Io;
>    with Trim;
>
>    procedure Trim_Test is
>
>       number : natural := 1234;
>
>    begin
>
>       Ada.Text_Io.Put_Line(Trim(natural'image(number)));
>
>    end Trim_Test;
>
>
> Hope this helps.
> Frank
>
> -----Original Message-----
> From: Tomas Hlavaty [mailto:hlavaty@labe.felk.cvut.cz]
> Sent: Wednesday, May 23, 2001 11:18 AM
> To: comp.lang.ada@ada.eu.org
> 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
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada





^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Natural to String without space? (newbie question)
@ 2001-05-24 21:55 Beard, Frank
  2001-05-25  7:30 ` Martin Dowie
  0 siblings, 1 reply; 14+ messages in thread
From: Beard, Frank @ 2001-05-24 21:55 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

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-----
From: Martin Dowie [mailto:martin.dowie@nospam.baesystems.com]

or,

   function Trim (Value : String;
                  Side  : Ada.Strings.Trim_End := Ada.Strings.Both)
      return String renames Ada.Strings.Fixed.Trim;


Beard, Frank <beardf@spawar.navy.mil> wrote in message
news:mailman.990658037.12046.comp.lang.ada@ada.eu.org...
> Probably the best way is:
>
> Make your own common function, such as:
>
>    with Ada.Strings;        use Ada.Srings;
>    with Ada.Strings.Fixed;  use Ada.Srings.Fixed;
>
>    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 Ada.Text_Io;
>    with Trim;
>
>    procedure Trim_Test is
>
>       number : natural := 1234;
>
>    begin
>
>       Ada.Text_Io.Put_Line(Trim(natural'image(number)));
>
>    end Trim_Test;
>
>
> Hope this helps.
> Frank
>
> -----Original Message-----
> From: Tomas Hlavaty [mailto:hlavaty@labe.felk.cvut.cz]
> Sent: Wednesday, May 23, 2001 11:18 AM
> To: comp.lang.ada@ada.eu.org
> 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
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada


_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Natural to String without space? (newbie question)
  2001-05-24 21:55 Beard, Frank
@ 2001-05-25  7:30 ` Martin Dowie
  2001-05-25  8:30   ` Tomas Hlavaty
                     ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Martin Dowie @ 2001-05-25  7:30 UTC (permalink / raw)


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

Beard, Frank <beardf@spawar.navy.mil> wrote in message
news:mailman.990741393.31666.comp.lang.ada@ada.eu.org...
> 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-----
> From: Martin Dowie [mailto:martin.dowie@nospam.baesystems.com]
>
> or,
>
>    function Trim (Value : String;
>                   Side  : Ada.Strings.Trim_End := Ada.Strings.Both)
>       return String renames Ada.Strings.Fixed.Trim;






^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Natural to String without space? (newbie question)
  2001-05-25  7:30 ` Martin Dowie
@ 2001-05-25  8:30   ` Tomas Hlavaty
  2001-05-25 15:05   ` Ehud Lamm
  2001-05-25 21:23   ` Ole-Hjalmar Kristensen
  2 siblings, 0 replies; 14+ messages in thread
From: Tomas Hlavaty @ 2001-05-25  8:30 UTC (permalink / raw)


Thanks.

Tomas



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Natural to String without space? (newbie question)
  2001-05-25  7:30 ` Martin Dowie
  2001-05-25  8:30   ` Tomas Hlavaty
@ 2001-05-25 15:05   ` Ehud Lamm
  2001-05-28  7:31     ` Martin Dowie
  2001-05-25 21:23   ` Ole-Hjalmar Kristensen
  2 siblings, 1 reply; 14+ messages in thread
From: Ehud Lamm @ 2001-05-25 15:05 UTC (permalink / raw)



Martin Dowie <martin.dowie@nospam.baesystems.com> wrote in message
news:3b0e0826$1@pull.gecm.com...
> 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?


--
Ehud Lamm   mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <==  Me!








^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Natural to String without space? (newbie question)
  2001-05-25  7:30 ` Martin Dowie
  2001-05-25  8:30   ` Tomas Hlavaty
  2001-05-25 15:05   ` Ehud Lamm
@ 2001-05-25 21:23   ` Ole-Hjalmar Kristensen
  2 siblings, 0 replies; 14+ messages in thread
From: Ole-Hjalmar Kristensen @ 2001-05-25 21:23 UTC (permalink / raw)


"Martin Dowie" <martin.dowie@nospam.baesystems.com> writes:

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,read);
   pragma Import(C,write);

end Uio;

> You're welcome, it's a nice little feature, isn't it? I
> was wuick surprised myself the first time I saw it. :-)
> 
> Beard, Frank <beardf@spawar.navy.mil> wrote in message
> news:mailman.990741393.31666.comp.lang.ada@ada.eu.org...
> > 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-----
> > From: Martin Dowie [mailto:martin.dowie@nospam.baesystems.com]
> >
> > or,
> >
> >    function Trim (Value : String;
> >                   Side  : Ada.Strings.Trim_End := Ada.Strings.Both)
> >       return String renames Ada.Strings.Fixed.Trim;
> 
> 
> 

-- 
Kabelsalat ist gesund.

Ole-Hj. Kristensen



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Natural to String without space? (newbie question)
  2001-05-25 15:05   ` Ehud Lamm
@ 2001-05-28  7:31     ` Martin Dowie
  0 siblings, 0 replies; 14+ messages in thread
From: Martin Dowie @ 2001-05-28  7:31 UTC (permalink / raw)


that would seem to be the case given LM 8.5.5.

> But it seems you can't do this with generic parameters. Right?
>
>
> --
> Ehud Lamm   mslamm@mscc.huji.ac.il
> http://purl.oclc.org/NET/ehudlamm <==  Me!






^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Natural to String without space? (newbie question)
  2001-05-24  6:33 ` Pascal Obry
@ 2001-05-29 21:04   ` Wes Groleau
  2001-05-29 23:00     ` Jeffrey Carter
  2001-05-30  7:19     ` Pascal Obry
  0 siblings, 2 replies; 14+ messages in thread
From: Wes Groleau @ 2001-05-29 21:04 UTC (permalink / raw)



> 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



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Natural to String without space? (newbie question)
  2001-05-29 21:04   ` Wes Groleau
@ 2001-05-29 23:00     ` Jeffrey Carter
  2001-05-30  7:19     ` Pascal Obry
  1 sibling, 0 replies; 14+ messages in thread
From: Jeffrey Carter @ 2001-05-29 23:00 UTC (permalink / raw)


Wes Groleau wrote:
> 
> > 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



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Natural to String without space? (newbie question)
  2001-05-29 21:04   ` Wes Groleau
  2001-05-29 23:00     ` Jeffrey Carter
@ 2001-05-30  7:19     ` Pascal Obry
  1 sibling, 0 replies; 14+ messages in thread
From: Pascal Obry @ 2001-05-30  7:19 UTC (permalink / raw)



Wes Groleau <wwgrol@ftw.rsc.raytheon.com> writes:

> > 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.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2001-05-30  7:19 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-23 15:17 Natural to String without space? (newbie question) Tomas Hlavaty
2001-05-23 22:37 ` DuckE
2001-05-24  6:33 ` Pascal Obry
2001-05-29 21:04   ` Wes Groleau
2001-05-29 23:00     ` Jeffrey Carter
2001-05-30  7:19     ` Pascal Obry
  -- strict thread matches above, loose matches on Subject: below --
2001-05-23 22:45 Beard, Frank
2001-05-24  7:56 ` Martin Dowie
2001-05-24 21:55 Beard, Frank
2001-05-25  7:30 ` Martin Dowie
2001-05-25  8:30   ` Tomas Hlavaty
2001-05-25 15:05   ` Ehud Lamm
2001-05-28  7:31     ` Martin Dowie
2001-05-25 21:23   ` Ole-Hjalmar Kristensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox