Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Borland > Re: String and ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 13 Topic 1025 of 1114
Post > Topic >>

Re: String and Char handling limitations:

by Femme Verbeek <fv@[EMAIL PROTECTED] > Apr 26, 2007 at 06:28 PM

CheckWilliamOut schreef:
> 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(tem****ary_file, data);
> until data = ' ';
> 
> Then I close the tem****ary 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:
> 

I don't see the problem.
If you open two files (as text) you can continue reading whole lines 
from the first one until it reaches the eof state

Read a complete line into a string variabele using readln instead of read.
Replace any word you want, and write the altered line to the destination 
file.


var sourcefile,targetfile:text;
var s:string;
......
While not eof (sourcefile) do
begin
   readln (sourcefile,s);
   processtheline;
   writeln (targetfile,s)
end;


> 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
> 

You are probably looking for the POS function. It searches for a 
substring in a string.

e.g.
const s:string='hello world hello computer';
var position:integer;
begin
   repeat
     position:=  pos('hello',s);
     if position>0 then
     begin
       delete(s,position,length('hello') ) ;
       insert('goodbye',s,position);
     end;
   until position=0;
   writeln(s);
end.

--  Femme
 




 13 Posts in Topic:
String and Char handling limitations:
CheckWilliamOut <wdupl  2007-04-25 15:13:54 
Re: String and Char handling limitations:
Wolf Behrenhoff <NoSpa  2007-04-26 12:07:07 
Re: String and Char handling limitations:
Wolf Behrenhoff <NoSpa  2007-04-26 12:19:16 
Re: String and Char handling limitations:
Femme Verbeek <fv@[EMA  2007-04-26 18:28:22 
Re: String and Char handling limitations:
Jyrki Lahtonen <lahton  2007-04-26 23:10:07 
Re: String and Char handling limitations:
Marco van de Voort <ma  2007-04-27 21:44:33 
Re: String and Char handling limitations:
CheckWilliamOut <wdupl  2007-05-05 03:31:57 
Re: String and Char handling limitations:
"Jochen" <jo  2007-05-05 16:16:09 
Re: String and Char handling limitations:
Jyrki Lahtonen <lahton  2007-05-07 23:44:27 
Re: String and Char handling limitations:
Marco van de Voort <ma  2007-05-07 20:50:56 
Re: String and Char handling limitations:
Jyrki Lahtonen <lahton  2007-05-08 00:10:34 
Re: String and Char handling limitations:
"Jochen" <jo  2007-05-08 01:24:33 
Re: String and Char handling limitations:
Tony Stanford <tonysta  2007-05-08 14:42:41 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 6 2:19:52 CDT 2008.