Dear all,
Why does Pascal limit functions you can perform on Strings and Chars.
There are two functions
in particular that only work with Intergers and other number types:
The Case statment and the "and", "or" and "xor" operators. Check these
illegal examples:
----------------------------------------------
var
This_word : string[30];
Begin
Case This_word of
'hello' : Write('Greetings');
'done' : Write('It is Finished');
end;
end.
----------------------------------------------
var
This_letter : char;
begin
If this_letter <> 'a' or 'b' then
Writeln('Neither A nor B were detected');
end.
----------------------------------------------
Is there another way perform these operations on a string or
character?
My purpose is to extract certain words from a text file, then convert
them to something else and write the conversions in a new text file.
For example: I want to open My_Text_File extract or search for all
occurances of "one" then make the program convert it to "1" and then
write the conversions (including any unconverted words) in
a new text file.
The problem is, I'm having trouble extracting only the words I want--
and getting the program to ignore spaces, commas, quotation marks,
carriage returns, and every other symbol and punctuation mark on the
keyboard.
First I tried using
repeat
Read(text_file, data);
Write(temporary_file, data);
until data = ' ';
Then I close the temporary file, and re-open it for reading, read the
characters--or the word--that has been stored there, then match it and
convert.
However that method is causing an infinite loop and there is no way a
"While not EOF" command can be used successfully to avoid the infinite
loop. This also causes problems because I want the computer to
recognize:
then
as being = to
Then
then.
then,
then!
"then"
then."
then?
and any other combination you can think of
Also when it comes to the end of a file, it doesn't find anymore
spaces and that is what is causing the infinit loop.
Ideally I want to be able to define the "until" part as:
until data <> 'a'..'z' or 'A'..'Z';
Sadly you can only do that with integers!
Perhaps in the above example if I change each letter to it's numeric
equivalent?
CheckWilliamOut


|