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,21162150cec9bc17 X-Google-Attributes: gid103376,public From: Ehud Lamm Subject: Re: String Length Date: 1998/10/02 Message-ID: #1/1 X-Deja-AN: 397100541 References: <36140400.0@news.cyberenet.net> <6v2ggj$p73$1@cf01.edf.fr> Content-Type: TEXT/PLAIN; charset=US-ASCII Organization: The hebrew University of Jerusalem Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-10-02T00:00:00+00:00 List-Id: First let me give two approaches that work: -- CODE FOLLOWS with ada.strings.unbounded; use ada.strings.unbounded; procedure try_strings is s:string := "ehud lamm"; begin put(s'length); put(length(to_unbounded_string("ehud"))); end; -- END OF CODE There are huge diffrences between the two methods used above. The second way (converting to an unbounded string) is costlier in any respect. I urge you to understand this. The first solution, using the attribute 'length on a String type variable is nice, since it results in a static expression. One confusing detail may be, that since String itself is an indefinite type (it is basically an unconstraint array type), you can not do something like this: -- WARNNING BAD CODE AHEAD s:String i:iinteger; begin s:="ehud"; i:=s'length; end; -- SAFE AGAIN You simply can not declare variables of type string without contraining it to some fixed length. When you say s:string:="ehud", the complier knows the length needed for s, by looking at the initialization. One final note: You can not say: "ehud"'length. This attribute will not work on a value, it wants a variable. Hope this helps! Ehud Lamm mslamm@pluto.mscc.huji.ac.il