From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,273f68be0dc28cef X-Google-Attributes: gid103376,public From: Samuel Mize Subject: Re: String to Integer Date: 1997/07/16 Message-ID: <33CD07B9.3DFA@link.com>#1/1 X-Deja-AN: 257274400 References: <5qglt7$cba$1@news.fsu.edu> Organization: Hughes Training Inc. Reply-To: smize@link.com Newsgroups: comp.lang.ada Date: 1997-07-16T00:00:00+00:00 List-Id: Charles Hill wrote: > > I have a string in which an integer is stored. I'd like to hear > from someone who might know a convenient way to convert this to > an actual integer. I'm wondering if there is a function built > into one of the Ada packages to do this, but I haven't found one > yet. > > I would appreciate any advice anyone has. Do you mean that the string contains the characters that represent the number, or that the string storage is also used as binary storage for an integer? In the first case (e.g. "301") you can use integer'image and integer'value to translate between the string and the integer value. If your string is a buffer that may have garbage after the end of the number (e.g., a null-terminated varying-length string in a fixed-length buffer), it may be simpler to use Ada.Text_Io.Integer_Io.Get from string, since it stops at the first non-numeric character (while Integer'Value would try to translate the entire string, and fail if there is anything in it but the integer and blanks). If you have a binary representation of an integer in your string, you should use unchecked_conversion. Samuel Mize