TIP: Click on subject to list as thread! ANSI
echo: pascal
to: ALL
from: STEWART HONSBERGER
date: 1998-05-23 13:18:00
subject: Palindromes

'Hullo all! I've seen a lot of talk in the Pascal related newsgroups
(specifically comp.lang.pascal.borland and comp.lang.pascal.misc) about
palindromes, (IE: A function to determine whether or not a string is a
palindrome or not) and decided to take a crack at 'em. I don't NEED a 
function of this type or anything, but I thought it would be interesting to
try nonetheless :>
Here's the program I wrote to test, and wondered whether or not this was
the best way to go about it (No copyrights, reserved rights, or anything 
else, if you use it, give me credit if you want to, but I don't really care
either way  );
Program Palind;
(*
   Simple program to verify whether or not a string is a palindrome.
   by Stewart Honsberger, May 23, 1998
   palindrome - n. - a word, phrase, or sentence that reads
                     the same backward and forward (Ex:
                     name no one man).
*)
uses
  Crt;
var
  S: String;
function Palindrome(Forw: String): Boolean;
var
  Backw: String;
  i: Byte;
  b: Byte;
  l: Byte;
begin
  for i := 1 to Length(Forw) do
  begin
    if Forw[i] = ' ' then
    begin
      Delete(Forw, i, 1);
      Dec(i);
    end else Forw[i] := Upcase(Forw[i]);
  end;
  l := Length(Forw);
  Backw[0] := Chr(l);
  b := 1;
  for i := l downto 1 do
  begin
    Backw[i] := Forw[b];
    Inc(b);
  end;
  if Forw = Backw then Palindrome := TRUE else Palindrome := FALSE;
end;
begin
  ClrScr;
  WriteLn;
  repeat
    Write('Enter a string to test: ');
    ReadLn(S);
    if S = '' then Break;
    WriteLn;
    if Palindrome(S) then
    begin
      TextColor(15);
      WriteLn('"' + S + '" is a palindrome!')
    end else
    begin
      TextColor(4);
      WriteLn('"' + S + '" is not a palindrome.');
    end;
    Textcolor(7);
    WriteLn;
  until FALSE;
end.
Stewart Honsberger,
  blackdeath@tinys.oix.com
... A female programmer wears a G$
-!- GOPGP v1.11 
--- Squish/386 v1.11
---------------
* Origin: Blackdeath BBS - Private (1:229/604)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.