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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c7932390dcbd43b7 X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: I'm Stumped ... Date: 1997/04/27 Message-ID: #1/1 X-Deja-AN: 237789469 References: <33638FBE.715C@usa.net> Organization: New York University Newsgroups: comp.lang.ada Date: 1997-04-27T00:00:00+00:00 List-Id: Ben Carter asks: Is it possible to take a string with the value : '123' and turn it into the integer 123? Any Help would be appreciated :) Thanks For your time ... First, it is trivial to write code that does this, just write a loop that starts with zero and traverses the string from the back, multiplying what you have by 10 and adding in the next digit. It's just 2 or 3 lines of code. Second, let's see if we can learn how to find this in the RM. Bob Duff did a great job of the index, so we start from there. Look up string: String 3.6.3(4), A.1(37) string type 3.6.3(1) Hmmm! not much to be found there, well we are trying to convert from string to integer, so perhaps look up Integer: Integer 3.5.4(11), 3.5.4(21), A.1(12) OK, off we go to 3.5.4. Now what we want is operations on integer types, and we do not find it in 3.5.4, but a little looking in the table of contents shows us where we are: 3.5 Scalar Types 3.5.1 Enumeration Types 3.5.2 Character Types 3.5.3 Boolean Types 3.5.4 Integer Types 3.5.5 Operations of Discrete Types 3.5.6 Real Types 3.5.7 Floating Point Types 3.5.8 Operations of Floating Point Types 3.5.9 Fixed Point Types 3.5.10 Operations of Fixed Point Types And ah ha! Operations of Discrete types sounds right -- the reason we did not find anything specific on operations of integer types is that they are grouped together with discrete types. OK, let's go visit 3.5.5: And we find a list of attributes, let's glance through and see if there is anything useful (in fact how about searching this section for String: We first find Wide_Image, a little look shows us that goes the other way, but we are getting warm, search on, also it is for Wide_String. Image is the next hit, still not what we want. Searching on, we hit Wide_Value -- ah ha! getting very warm, but still works on Wide_String, one more search, and voila! 52 S'Value S'Value denotes a function with the following specification: 53 function S'Value(Arg : String) return S'Base 54 This function returns a value given an image of the value as a String, ignoring any leading or trailing spaces. And there we have it, so what you are looking for is IntegerVlue. Well it wasn't immediate (ch 3 is always tough), but we found it. I find it tremendously useful to have an ASCII version of the RM that I can just search around with in the editor. General note: I strongly that everyone peruse annex K of the RM, there are lots of useful attributes there which are worth knowing about (I keep seeing Ada 95 programmers who clearly do not know about max and min for example).