* String Manipulation
@ 1998-04-08 0:00 Howard Davies
0 siblings, 0 replies; 10+ messages in thread
From: Howard Davies @ 1998-04-08 0:00 UTC (permalink / raw)
Hi,
Many thanks to the two guys who took the time to suggest packages and
functions I should look at to manipulate strings in Ada. It proved to be
a great help and helped me solve my problems.
Its good to know that there are still some decent folks around.
Thanks again
--
Howard Davies Howard@roslyn.demon.co.uk
^ permalink raw reply [flat|nested] 10+ messages in thread
* String Manipulation
@ 1998-09-22 0:00 SiliconJesus
1998-09-23 0:00 ` David C. Hoos, Sr.
0 siblings, 1 reply; 10+ messages in thread
From: SiliconJesus @ 1998-09-22 0:00 UTC (permalink / raw)
I have run into a problem while writing a recent program.
I have a field in a record called name, which when I get input from a
specified data file it's Lastname, First well the problem is not in
inputting it, but when I update this record from another file, only the
last name is given. So how do I read a character at a time and put only
the last name in a temp variable so I can compare the two names so that
the rest of the record gets updated.
Thanks
,. '\'\ ,---.
| \\ l\\l_ // | ~NARF!!
| \\/ `/ `.| |
| Y | | || Y |
| \| | |\ / |
\ | o|o | > /
\___\_--_ /_/__/
/.-\(____) /--.\
`--(______)----'
U// U / \
/ \ / /|
==========================================================================
| John M. Softich | " I wanna live, I wanna love |
| softichj@cs.montana.edu | but it's a long hard |
| Montana State University | road out of hell! " |
| Http://cs.montana.edu/~softichj | ~Manson |
==========================================================================
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: String Manipulation
1998-09-22 0:00 SiliconJesus
@ 1998-09-23 0:00 ` David C. Hoos, Sr.
0 siblings, 0 replies; 10+ messages in thread
From: David C. Hoos, Sr. @ 1998-09-23 0:00 UTC (permalink / raw)
SiliconJesus wrote in message ...
>I have run into a problem while writing a recent program.
<snip>
Look at the Find_Token procedure in Ada.Strings.Fixed
^ permalink raw reply [flat|nested] 10+ messages in thread
* string manipulation
@ 2002-12-07 23:14 Gep
2002-12-07 23:20 ` Gep
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Gep @ 2002-12-07 23:14 UTC (permalink / raw)
Is it possible to declare a string to be exactly 10 characters long and
still be a variable? then
for example
declare V_string as being exactly 10 characters
while not valid
loop
get_line(V_string, V_length);
if v_Art_lng = t_Art_article.t_art_proprietaire.v_nas'length then
Skip_Line;
Valid := True;
else
valid :=false;
Put("invalid");
end if;
end loop;
anything not in the range of declared string (in this case being10) would be
declared as invalid...any ideas?
I dont want to to have any explicit statement of 10 like "if V_length = 10
then" in this little procedure as it will be getting strings of various
length.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: string manipulation
2002-12-07 23:14 string manipulation Gep
@ 2002-12-07 23:20 ` Gep
2002-12-08 2:24 ` Jeffrey Carter
2002-12-08 14:02 ` Marin David Condic
2002-12-08 0:07 ` Jacob Sparre Andersen
2002-12-08 0:12 ` James S. Rogers
2 siblings, 2 replies; 10+ messages in thread
From: Gep @ 2002-12-07 23:20 UTC (permalink / raw)
"Gep" <nodsa@sdfsffds.net> wrote in message
news:BhvI9.27495$Mn4.328936@wagner.videotron.net...
> Is it possible to declare a string to be exactly 10 characters long and
> still be a variable? then
> for example
>
> declare V_string as being exactly 10 characters
>
>
> while not valid
> loop
> get_line(V_string, V_length);
>
> if v_Art_lng = t_Art_article.t_art_proprietaire.v_nas'length then
> Skip_Line;
> Valid := True;
> else
> valid :=false;
> Put("invalid");
> end if;
>
> end loop;
oops the code should be as follows
while not valid
loop
get_line(V_string, V_length);
if V_length= V_string'length then
Skip_Line;
Valid := True;
else
valid :=false;
Put("invalid");
end if;
end loop;
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: string manipulation
2002-12-07 23:14 string manipulation Gep
2002-12-07 23:20 ` Gep
@ 2002-12-08 0:07 ` Jacob Sparre Andersen
2002-12-08 0:12 ` James S. Rogers
2 siblings, 0 replies; 10+ messages in thread
From: Jacob Sparre Andersen @ 2002-12-08 0:07 UTC (permalink / raw)
Gep wrote:
> Is it possible to declare a string to be exactly 10 characters long and
> still be a variable?
Yes:
V_String : String (1 .. 10);
Jacob
--
"I don't want to gain immortality in my works.
I want to gain it by not dying."
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: string manipulation
2002-12-07 23:14 string manipulation Gep
2002-12-07 23:20 ` Gep
2002-12-08 0:07 ` Jacob Sparre Andersen
@ 2002-12-08 0:12 ` James S. Rogers
2 siblings, 0 replies; 10+ messages in thread
From: James S. Rogers @ 2002-12-08 0:12 UTC (permalink / raw)
"Gep" <nodsa@sdfsffds.net> wrote in message
news:BhvI9.27495$Mn4.328936@wagner.videotron.net...
> Is it possible to declare a string to be exactly 10 characters long and
> still be a variable? then
You want to use the package Ada.Strings.Bounded.
This package allows you to specify a maximum string length,
and use data up to that length.
Jim Rogers
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: string manipulation
2002-12-07 23:20 ` Gep
@ 2002-12-08 2:24 ` Jeffrey Carter
2002-12-08 18:34 ` Gep
2002-12-08 14:02 ` Marin David Condic
1 sibling, 1 reply; 10+ messages in thread
From: Jeffrey Carter @ 2002-12-08 2:24 UTC (permalink / raw)
Gep wrote:
>
> while not valid
> loop
> get_line(V_string, V_length);
>
> if V_length= V_string'length then
> Skip_Line;
> Valid := True;
> else
> valid :=false;
> Put("invalid");
> end if;
> end loop;
This looks better then that other code. You can do this. It will
repeatedly get a line until it gets one that is exactly V_String'Length
characters. If that's what you want. I don't see what it has to do with
declaring a string variable of a specific length.
Valid is sort of useless here, as well as providing an opportunity for
errors. You can forget to assign to it, or assign the wrong value. I
think this would read better without it:
loop
Get_Line (...);
if V_Length = V_String'Length then
Skip_Line;
exit;
end if;
Put ("invalid");
end loop;
The purpose of the code is to exit the loop when a line of the right
length is read. It's better for the code to say that, then to hide it
behind a Boolean flag.
--
Jeff Carter
"Pray that there's intelligent life somewhere up in
space, 'cause there's bugger all down here on earth."
Monty Python's Meaning of Life
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: string manipulation
2002-12-07 23:20 ` Gep
2002-12-08 2:24 ` Jeffrey Carter
@ 2002-12-08 14:02 ` Marin David Condic
1 sibling, 0 replies; 10+ messages in thread
From: Marin David Condic @ 2002-12-08 14:02 UTC (permalink / raw)
It is technically possible, but the question seems to imply a bit of
confusion about the nature of the type String in Ada. String is a data type
that is an array - nothing more or less. Its element type is Character.
Hence, just as you can declare a type like:
type Vector is array (Integer range <>) of Float ;
and then make specific variables with specific numbers of elements:
My_Vector : Vector (1..10) ;
Your_Vector : Vector (20..50) ;
The exact same thing is legal in Ada for the type String. It is important to
understand that the 'Length doesn't have anything to do with the content of
the string - just the number of positions in the array.
The thing is that often programmers from other languages are used to strings
taking on dynamic sizes depending on what is assigned to them In C, it is
done - in a way - by including a null character somewhere in the array of
characters to indicate termination. This can be done in Ada as well, but is
highly unnatural and not recommended. If you are interested in strings with
a more dynamic nature, look at Ada.Strings.Bounded and Ada.Strings.Unbounded
in the ARM. (Also Ada.Strings.Fixed, if you want to deal with the standard
String type.) Both Bounded and Unbounded strings give you better ability to
look at the length of the string as a function of its content.
MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/
Send Replies To: m c o n d i c @ a c m . o r g
"I'd trade it all for just a little more"
-- Charles Montgomery Burns, [4F10]
======================================================================
Gep <nodsa@sdfsffds.net> wrote in message
news:ynvI9.27498$Mn4.329910@wagner.videotron.net...
>
> "Gep" <nodsa@sdfsffds.net> wrote in message
> news:BhvI9.27495$Mn4.328936@wagner.videotron.net...
> > Is it possible to declare a string to be exactly 10 characters long and
> > still be a variable? then
> > for example
> >
> > declare V_string as being exactly 10 characters
> >
> >
> > while not valid
> > loop
> > get_line(V_string, V_length);
> >
> > if v_Art_lng = t_Art_article.t_art_proprietaire.v_nas'length then
> > Skip_Line;
> > Valid := True;
> > else
> > valid :=false;
> > Put("invalid");
> > end if;
> >
> > end loop;
>
>
> oops the code should be as follows
>
> while not valid
> loop
> get_line(V_string, V_length);
>
> if V_length= V_string'length then
> Skip_Line;
> Valid := True;
> else
> valid :=false;
> Put("invalid");
> end if;
> end loop;
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: string manipulation
2002-12-08 2:24 ` Jeffrey Carter
@ 2002-12-08 18:34 ` Gep
0 siblings, 0 replies; 10+ messages in thread
From: Gep @ 2002-12-08 18:34 UTC (permalink / raw)
"Jeffrey Carter" <jrcarter@acm.org> wrote in message
news:3DF2AD96.6010100@acm.org...
> Gep wrote:
> >
> > while not valid
> > loop
> > get_line(V_string, V_length);
> >
> > if V_length= V_string'length then
> > Skip_Line;
> > Valid := True;
> > else
> > valid :=false;
> > Put("invalid");
> > end if;
> > end loop;
>
> This looks better then that other code. You can do this. It will
> repeatedly get a line until it gets one that is exactly V_String'Length
> characters. If that's what you want. I don't see what it has to do with
> declaring a string variable of a specific length.
>
> Valid is sort of useless here, as well as providing an opportunity for
> errors. You can forget to assign to it, or assign the wrong value. I
> think this would read better without it:
>
> loop
> Get_Line (...);
>
> if V_Length = V_String'Length then
> Skip_Line;
>
> exit;
> end if;
>
> Put ("invalid");
> end loop;
>
What I wanted is a procedure that couldget both, a string with a fixed
length or a variable length. But it is ok I'm gonna done do two seprate
procedures. I thnik it is going to be more clear that way
thanks anyway for help.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2002-12-08 18:34 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-08 0:00 String Manipulation Howard Davies
-- strict thread matches above, loose matches on Subject: below --
1998-09-22 0:00 SiliconJesus
1998-09-23 0:00 ` David C. Hoos, Sr.
2002-12-07 23:14 string manipulation Gep
2002-12-07 23:20 ` Gep
2002-12-08 2:24 ` Jeffrey Carter
2002-12-08 18:34 ` Gep
2002-12-08 14:02 ` Marin David Condic
2002-12-08 0:07 ` Jacob Sparre Andersen
2002-12-08 0:12 ` James S. Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox