Tuesday
4/16/02 Chapter 10
Student Notes
Objectives
Strings
Files
1. The
String Data Type
- We have all ready worked with Strings for most of
the semester
- a string is an
- it is possible to assign or refer to a
- Strings can be assigned to each other, but their
- Strings can be to
form longer strings
2.
String vs. Character
- it is possible to have a String on only one
character, however
“A” /= ‘A’
3.
Dealing with strings of variable length
- Ada.Text_IO.Get_Line allows us to count the number of continuous,
non-white space characters in an input stream
- NameLength : Natural;
- Ada.Text_IO.Get_Line(Item
=> LastName, Last => NameLength);
- LastName must be a string of a predefined length,
and if the input string is shorter than LastName, the characters after
position NameLength are
-
-
4.
String Slicing
·
FirstName(1..4)
·
LastName(5..11)
·
These are slices of the strings FirstName and
LastName. the first through fourth characters of FirstName and the fifth
through eleventh characters of LastName
·
Ada.Text_IO.Put(Item=>LastName(1..NameLength);
·
This uses the
number of defined characters for
output. This is very nice for formatting text
5.
String Mapping packages
- Ada provides some packages for automatically mapping
on character into another
- page 441
6.
Text files
- Text files may used for reading or writing but
-
-
- The size of the text file is not limited.
- The end of a file is designated by a special
-
- this is called a
-
- Then end of a line is specified by a
-
-
- This is a text file.
<eol>
- It has two lines.
<eol><eof>
-
-
- The key board can be viewed as file input as well
- We can detect an <eol> or <eof> by
using the End_Of_Line
or End_Of_File functions in Ada
- LOOP
EXIT WHEN
Ada.Text_IO.End_Of_Line(data file)
some program
statements
END LOOP
7.
Getting Input values from a String
- We can read data in from a string as well as from
a file or from Standard Input (the key board)
- If we have a string of tokens as we expect he
first token to be an integer, we can get that integer from the string
- page 459
8.
Command Line Parameters
- Often times we would like the user to be able to
start the program and give us some initial values (ex. sortfile.exe myfile.dat)
- Ada provides a packages for handling command line
data Ada.Command_Line
- page 460