comp.lang.ada
 help / color / mirror / Atom feed
* Re: End of a string????
  2000-10-10  0:00 End of a string???? Ryuji Yokoyama
  2000-10-10  0:00 ` Ted Dennison
@ 2000-10-10  0:00 ` tmoran
  2000-10-13  0:00 ` Per Sandberg
  2 siblings, 0 replies; 7+ messages in thread
From: tmoran @ 2000-10-10  0:00 UTC (permalink / raw)


>How can I find the end of string in ada?  Is there any special character
>at the end of line like C's \0?  Or is there any function to find the
>length of a string like Java's Mystring.length()?  I tried
>myString'length, but it just gives me the size of array.
  S : String(1 .. 5);
is an array of 5 Characters, ie, a 5 character long string, regardless
of the contents of S.  An ascii.nul has no special meaning to Ada.
  You may want to look at package Ada.Strings.Bounded (for variable length
with a fixed maximum, like C) or at Ada.Strings.Unbounded (for variable
length with additional space allocated as needed).




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

* Re: End of a string????
  2000-10-10  0:00 End of a string???? Ryuji Yokoyama
@ 2000-10-10  0:00 ` Ted Dennison
  2000-10-10  0:00 ` tmoran
  2000-10-13  0:00 ` Per Sandberg
  2 siblings, 0 replies; 7+ messages in thread
From: Ted Dennison @ 2000-10-10  0:00 UTC (permalink / raw)


In article <MPG.144cf9c2da936cef98968d@news.prodigy.net>,
  Ryuji Yokoyama <stiletto@ryuji.net> wrote:

> How can I find the end of string in ada?  Is there any special
> character at the end of line like C's \0?  Or is there any function
> to find the length of a string like Java's Mystring.length()?  I
> tried myString'length, but it just gives me the size of array.

In Ada the length of the string *is* the length of the array.

If you have some kind of logical end of the data within the string, you
either have to create your string object exactly that length, or keep
track of the end index in a separate variable and use subranges (eg:
"MyString(1..MyString_Length)" ).

As Tom mentioned, another option is to use
Ada.Strings.Unbounded.Unbounded_String or
Ada.Strings.Bounded.Bounded_String, which will allow you to use
varying-length strings without having to use subranges. But if the
string doesn't change after it gets its initial value, you are probably
better off just declaring it there with the exact size you will need.

For more information on this subject, consult our FAQ at
http://www.adapower.com/lab/adafaq/24.html .


--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html
Day 5 of Free Europe


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* End of a string????
@ 2000-10-10  0:00 Ryuji Yokoyama
  2000-10-10  0:00 ` Ted Dennison
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Ryuji Yokoyama @ 2000-10-10  0:00 UTC (permalink / raw)



Hello all!

How can I find the end of string in ada?  Is there any special character 
at the end of line like C's \0?  Or is there any function to find the 
length of a string like Java's Mystring.length()?  I tried 
myString'length, but it just gives me the size of array.




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

* Re: End of a string????
  2000-10-10  0:00 End of a string???? Ryuji Yokoyama
  2000-10-10  0:00 ` Ted Dennison
  2000-10-10  0:00 ` tmoran
@ 2000-10-13  0:00 ` Per Sandberg
  2000-10-13  0:00   ` Wes Groleau
  2 siblings, 1 reply; 7+ messages in thread
From: Per Sandberg @ 2000-10-13  0:00 UTC (permalink / raw)


If your construct is 
	procedure foo( s : string) is ...

And you want to know the last char of the string the answer is 
	s'last

The first is:
	s'first

The length is:
	s'length

and finaly if you want to loop over it, the loop construct is
	for index in s'range loop
		..
		..
	end loop;

This is if you are working with the basic string-type in Ada.

/Per Sandberg




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

* Re: End of a string????
  2000-10-13  0:00 ` Per Sandberg
@ 2000-10-13  0:00   ` Wes Groleau
  2000-10-13  0:00     ` David C. Hoos, Sr.
  0 siblings, 1 reply; 7+ messages in thread
From: Wes Groleau @ 2000-10-13  0:00 UTC (permalink / raw)


Just in case we're talking to a newcomer, let's be precise:

> If your construct is
>         procedure foo( s : string) is ...
> 
> And you want to know the last char of the string the answer is

         s(s'last)

> The length is:

         s(s'first)

-- 
Wes Groleau
http://freepages.genealogy.rootsweb.com/~wgroleau




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

* Re: End of a string????
  2000-10-13  0:00   ` Wes Groleau
@ 2000-10-13  0:00     ` David C. Hoos, Sr.
  2000-10-14  0:00       ` Wes Groleau
  0 siblings, 1 reply; 7+ messages in thread
From: David C. Hoos, Sr. @ 2000-10-13  0:00 UTC (permalink / raw)



"Wes Groleau" <wwgrol@ftw.rsc.raytheon.com> wrote in message
news:39E74034.9C8116C@ftw.rsc.raytheon.com...
> Just in case we're talking to a newcomer, let's be precise:
>
> > If your construct is
> >         procedure foo( s : string) is ...
> >
> > And you want to know the last char of the string the answer is
>
>          s(s'last)
>
> > The length is:
>
>          s(s'first)
Whaaaaaaaat??? How precise (correct) is the above?
>
> --
> Wes Groleau
> http://freepages.genealogy.rootsweb.com/~wgroleau






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

* Re: End of a string????
  2000-10-13  0:00     ` David C. Hoos, Sr.
@ 2000-10-14  0:00       ` Wes Groleau
  0 siblings, 0 replies; 7+ messages in thread
From: Wes Groleau @ 2000-10-14  0:00 UTC (permalink / raw)



> > > The length is:
> >
> >          s(s'first)
> Whaaaaaaaat??? How precise (correct) is the above?

Oops - deleted the wrong line.

The FIRST CHARACTER is s(s'first).

What I was trying to say is that s'first is NOT the
first character--it is the first index.

It's typos like this--obvious, yet somehow missed by
the writer--that demonstrate why a "picky" language is
not a ball and chain as some want us to believe.

-- 
Wes Groleau
http://freepages.genealogy.rootsweb.com/~wgroleau




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

end of thread, other threads:[~2000-10-14  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-10  0:00 End of a string???? Ryuji Yokoyama
2000-10-10  0:00 ` Ted Dennison
2000-10-10  0:00 ` tmoran
2000-10-13  0:00 ` Per Sandberg
2000-10-13  0:00   ` Wes Groleau
2000-10-13  0:00     ` David C. Hoos, Sr.
2000-10-14  0:00       ` Wes Groleau

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