Input from keyboard with restriction length
Delphi & Pascal (česká wiki)
Category: KMP (Club of young programmers)
Author: Lukáš Hlousek
Program: Inpstr.pas
Author: Lukáš Hlousek
Program: Inpstr.pas
Input from keyboard with restriction length.
{ INPSTR.PAS Copyright (c) Lukas Hlousek } { Vstup z klavesnice s omezenim poctu znaku. } { } { Datum:10.01.2007 http://www.trsek.com } uses Crt; const CR=#13; BS=#8; Num=['0','1','2','3','4','5','6','7','8','9']; var InpBuf: string; InpChr: char; MaxLen: byte; begin MaxLen:=8; ClrScr; InpChr:=#0; InpBuf:=''; while InpChr<>#13 do begin InpChr:=ReadKey; case InpChr of BS: Delete(InpBuf,Length(InpBuf),1); else if (Length(InpBuf)<MaxLen) AND (InpChr in Num) then InpBuf:=InpBuf+InpChr; end; GotoXY(1,1); ClrEol; Write(InpBuf); end; end.