AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Home >
Articles >
Getting Started >
Ada FAQ >
Source Treasury >
Books & Tutorials >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
Searching in a String (David Botton)

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants;

procedure SS is
   S : String := "This is this IS a TeSt String";
begin
   Put_Line ("Search for ""this""");
   Put_Line (Natural'Image (Index (S, "this")));

   Put_Line ("Search for ""this"" but look at the Source string as if it " &
               "was lower case");
   Put_Line (Natural'Image (Index (Source  => S,
                                   Pattern => "this",
                                   Mapping => Lower_Case_Map)));

   Put_Line ("Search for ""this"" but look at the Source string as if it " &
               "was lower case, but look for latest found in string of " &
               "pattern");
   Put_Line (Natural'Image (Index (Source  => S,
                                   Pattern => "this",
                                   Going   => Ada.Strings.Backward,
                                   Mapping => Lower_Case_Map)));

   Put_Line ("Search for ""this"" but look at the Source string as if it " &
               "was upper case");
   Put_Line (Natural'Image (Index (Source  => S,
                                   Pattern => "this",
                                   Mapping => Upper_Case_Map)));

   Put_Line ("Search for ""test"" but look at the Source string as if it " &
               "was lower case, but look start after the 9th character");
   Put_Line (Natural'Image (Index (Source  => S (S'First + 9 .. S'Last),
                                   Pattern => "test",
                                   Mapping => Lower_Case_Map)));


end SS;


(c) 1998-2004 All Rights Reserved David Botton