From: sk <noname@myob.com>
Subject: Re: String slicing.
Date: Mon, 18 Mar 2002 06:44:53 -0600
Date: 2002-03-18T06:44:53-06:00 [thread overview]
Message-ID: <mailman.1016455503.7637.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: AH8l8.64181$uA5.64687@rwcrnsc51.ops.asp.att.net
Hi,
If you are using Gnat, type "gnatpsta" at the command-line and
you will be provided the following :
type Integer is range -(2 ** 31) .. +(2 ** 31 - 1);
subtype Natural is Integer range 0 .. +(2 ** 31 - 1);
subtype Positive is Integer range 1 .. +(2 ** 31 - 1);
...
type String is array (Positive range <>) of Character;
pragma Pack
(String);
So in the simplest terms, a string is a numerically indexed
array of characters.
declare
-- SB, SE --> String_Begins, String_Ends
SB, SE : Natural := 0;
Sample_String : constant String := "Hello Cruel World";
begin
-- Find first ' '
for i in Sample_String'Range loop
if Sample_String (I) = ' ' then
SB := i;
exit;
end if;
end loop;
...
-- Pretend that the second ' ' has been found.
TIO.Put_Line (
"The World is such a " &
Sample_String (SB .. SE) &
" place."
);
end;
In general, unless you are searching for control characters,
specify them in the source or use named characters.
For example,
Html_Tag_Open : constant Character := '<';
Html_Tag_Close : constant Character := '>';
Horizontal_Tab : constant Character :=
Ada.Characters.Latin_1.HT;
Also, you don't need to introduce the heavy-weight
Ada.Strings.xxx unless your application is more
complex than the one above. Even then, I personally
just write small string-searchers within the application
rather than introduce the Ada.Strings.xxx
Hope this helps.
--
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
k i e k c c m
-------------------------------------
next prev parent reply other threads:[~2002-03-18 12:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-03-17 22:23 String slicing Wannabe h4x0r
2002-03-17 22:43 ` Jim Rogers
2002-03-17 23:53 ` Wannabe h4x0r
2002-03-18 12:44 ` sk [this message]
2002-03-19 2:36 ` Wannabe h4x0r
2002-03-18 17:49 ` Georg Bauhaus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox