{ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA } unit Strings; interface const CR = #13; LF = #10; BS = #8; F1 = #187; F2 = #188; F3 = #189; F4 = #190; F5 = #191; F6 = #192; F7 = #193; F8 = #194; F9 = #195; F10 = #196; C_up = #200; C_dn = #208; C_lt = #203; C_rt = #205; Endk = #207; Home = #199; PgDn = #209; PgUp = #201; Del = #211; Ins = #210; AltX = #173; function GetKey: char; function NrFields(S: string; Sep: char): integer; function Field_Nr(S: string; Sep: char; Nr: integer): string; function HexB(B: byte): string; function HexW(W: word): string; function BinB(B: byte): string; implementation uses CRT; function GetKey: char; var Ch: char; begin Ch := ReadKey; if Ch = #0 then begin Ch := ReadKey; Ch := chr(ord(Ch) + 128); end; GetKey := Ch; end; function NrFields(S: string; Sep: char): integer; var Nr, C: integer; begin Nr := 1; for C := 1 to length(S) do if S[C] = Sep then inc(Nr); NrFields := Nr; end; function Field_Nr(S: string; Sep: char; Nr: integer): string; var P, F: integer; begin Field_Nr := ''; if NrFields(S, Sep) < Nr then exit; for F := 1 to Nr-1 do begin P := pos(',', S); S := copy(S, P+1, length(S)-P); end; P := pos(',', S); if P = 0 then Field_Nr := S else Field_Nr := copy(S, 1, P-1); end; function HexB(B: byte): string; const HexV: string[16] = '0123456789ABCDEF'; begin HexB := HexV[B div 16 + 1] + HexV[B mod 16 + 1]; end; function HexW(W: word): string; begin HexW := HexB(W shr 8) + HexB(W and $FF); end; function BinB(B: byte): string; var Bit: integer; S: string[8]; begin S := ''; for Bit := 0 to 7 do S := chr(48 + (B shr Bit) and 1) + S; BinB := S; end; begin end.