From: dale@cs.rmit.edu.au (Dale Stanbrough)
Subject: Re: compare a string variable with a string literal
Date: 1998/10/11
Date: 1998-10-10T22:58:58+00:00 [thread overview]
Message-ID: <dale-1110980900410001@dale.ppp.cs.rmit.edu.au> (raw)
In-Reply-To: fTPT1.117$ur3.1421326@news.rdc1.tx.home.com
Someone wrote:
" How do you compare a string variable with a string literal?? It's not
working.
Please post and email response if possible."
It does work very well. No doubt you are doing...
X : string (1..100);
Last : Natural;
...
Get_Line (X, Last);
...
if X = "hello" then...
this will of course return false, because a 5 character string cannot equal
a 100 character string. Ada strings _do not_ work like C strings - there is
no terminating character at the end of the valid input.
If you want to store variable length strings then use ada.strings.unbounded...
with ada.strings.unbounded; use ada.strings.unbounded;
...
X : string (1..100);
Last : Natural;
Y : unbounded_string;
get_line (x, last);
y : = to_unbounded_string (X (1..last));
if y = "hello" then
this _will_ do what you want it to.
Dale
prev parent reply other threads:[~1998-10-11 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-10-10 0:00 compare a string variable with a string literal H�x�d��m�
1998-10-10 0:00 ` Matthew Heaney
1998-10-11 0:00 ` Dale Stanbrough [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox