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


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:

   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

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
_______________________________________________
comp.lang.ada mailing list

http://ada.eu.org/mailman/listinfo/comp.lang.ada



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;

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"



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

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


Quote:
> 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-----

> 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
> _______________________________________________
> comp.lang.ada mailing list

> http://ada.eu.org/mailman/listinfo/comp.lang.ada



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;
                  Side  : Ada.Strings.Trim_End := Ada.Strings.Both)
      return String renames Ada.Strings.Fixed.Trim;



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

> 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
> _______________________________________________
> comp.lang.ada mailing list

> http://ada.eu.org/mailman/listinfo/comp.lang.ada

_______________________________________________
comp.lang.ada mailing list

http://ada.eu.org/mailman/listinfo/comp.lang.ada



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;
>                   Side  : Ada.Strings.Trim_End := Ada.Strings.Both)
>       return String renames Ada.Strings.Fixed.Trim;



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,read);
   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;
> >                   Side  : Ada.Strings.Trim_End := Ada.Strings.Both)
> >       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.

--

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



Sun, 16 Nov 2003 15:19:07 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. newbie question: getting rid of space in string :(

2. Newbie question: behaviour of String === String

3. newbie question: Haskell foldr space efficiency

4. Name spaces, newbie question

5. Newby question - Trimming spaces from a string

6. J Question: Unboxing arrays of strings without padding

7. Newbie question: creating dll without the need of CVF 6.6 Runtime library

8. Newbie Questions: PRINT without cr

9. newbie question: printing all matches without interaction

10. newbie question: lsearch without case match

11. Newbie question about running scripts without console

12. newbie question- variable strings

 

 
Powered by phpBB® Forum Software