{$D-} Unit Data; Interface {***************************************************************************} {***************************************************************************} Function DropBlanks(InStr: string): string; function DropBlanksEnd(InStr: string): string; procedure DropLeadBlanks(var InStr: string); procedure GetQuote(var QuoteStr: string); Function IntStr(InStr: string): longint; function MultiChar(RepeatChar: char; NumTimes: integer): string; procedure PosChars(SearchChars: string; InStr: string; var Position: integer; var CharFound: char); function SplitOn(SearchChars: string; InStr: string; var Half1, Half2: string; var CharFound: char): boolean; procedure PosString(SearchStr, InStr: string; var Position: integer); Function StrByte(InByte: byte): string; function StrInt(NumInt: longint): string; function StrIntLen(NumInt: longint; IntLen: integer): string; function StrIntSig(NumInt: longint; IntLen: byte): string; Function StrIntZer(NumIn: longint; NumLen: integer): string; Function StrPhone(InStr: string): string; function StrReal(Number: real; Width, Decimals: integer): string; function StrSized(InStr: string; Size: byte): string; function StrSizedLead(InStr: string; Size: byte): string; Function StrStripNonNum(InStr: string): string; Function StrWrdZer(NumWrd: word; WrdLen: integer): string; Function UpCaseFirstLetters(InStr: string): string; function UpCaseStr(InStr: string): string; function WildCardFormat(FormatStr: string; InStr: string): boolean; Implementation {***************************************************************************} {***************************************************************************} uses Glob; Function DropBlanks(InStr: string): string; {***************************************************************************} var Index: byte; Temp: string; begin Temp := ''; for Index := 1 to length(InStr) do if InStr[Index] <> ' ' then Temp := Temp + InStr[Index]; DropBlanks := Temp; end; function DropBlanksEnd(InStr: string): string; {***************************************************************************} var Temp: string; begin Temp := InStr; while Temp[length(Temp)] = ' ' do Temp := copy(Temp, 1, length(Temp) - 1); DropBlanksEnd := Temp; end; procedure DropLeadBlanks(var InStr: string); {***************************************************************************} begin while Pos(' ',InStr) = 1 do InStr := copy(InStr, 2, length(InStr) - 1); end; procedure GetQuote(var QuoteStr: string); {***************************************************************************} {* Gets a string between two quotes ("). If there is no second quote, {* will report all of the string left after the first quote. {***************************************************************************} var FirstQuotePos, NextQuotePos: integer; begin FirstQuotePos := Pos('"', QuoteStr); NextQuotePos := Pos('"', copy(QuoteStr, FirstQuotePos + 1, length(QuoteStr) - FirstQuotePos)); if NextQuotePos = 0 then NextQuotePos := length(QuoteStr) + 1; QuoteStr := copy(QuoteStr, FirstQuotePos+1, NextQuotePos -1); end; Function IntStr(InStr: string): longint; {***************************************************************************} var TempIntStr: longint; begin val(InStr, TempIntStr, DumInt); IntStr := TempIntStr; end; function MultiChar(RepeatChar: char; NumTimes: integer): string; {***************************************************************************} var TempMultiChar: string; alpha: integer; begin TempMultiChar := ''; for alpha := 1 to NumTimes do TempMultiChar := TempMultiChar + RepeatChar; MultiChar := TempMultiChar; end; procedure PosChars(SearchChars: string; InStr: string; var Position: integer; var CharFound: char); {***************************************************************************} {* Position is where it starts looking and where it stops. {* Returns first character found and its position. {* If no character found, then Position is one > length InStr and {* CharFound = #0; {***************************************************************************} var LenInStr, LenSearchChars: integer; alpha, bravo: integer; NewPosition: integer; begin LenInStr := length(InStr); LenSearchChars := length(SearchChars); ; CharFound := #0; ; for alpha := Position to LenInStr do begin for bravo := 1 to LenSearchChars do begin if InStr[alpha] = SearchChars[bravo] then begin CharFound := SearchChars[bravo]; bravo := LenSearchChars; NewPosition := alpha; alpha := LenInStr; end else NewPosition := alpha + 1; end; end; Position := NewPosition; end; procedure PosString(SearchStr, InStr: string; var Position: integer); {***************************************************************************} {* Position is the start search location and the position where found. {* If not found, Position set to length of InStr + 1. {***************************************************************************} var PositionSave, LenInStrSave: integer; begin PositionSave := Position; LenInStrSave := length(InStr); InStr := copy(InStr, Position, length(InStr) - (Position - 1)); Position := Pos(SearchStr, InStr); if Position = 0 then Position := LenInStrSave + 1 else Position := Position + PositionSave - 1; end; function SplitOn(SearchChars: string; InStr: string; var Half1, Half2: string; var CharFound: char): boolean; {***************************************************************************} var Position: integer; Temp: boolean; begin Position := 1; PosChars(SearchChars, InStr, Position, CharFound); Temp := Position <> length(InStr) + 1; if Temp then begin Half1 := copy(InStr, 1, Position - 1); Half2 := copy(InStr, Position + 1, length(InStr) - Position); end; SplitOn := Temp; end; Function StrByte(InByte: byte): string; {***************************************************************************} var OutStr: string; begin Str(InByte, OutStr); StrByte := OutStr; end; function StrInt(NumInt: longint): string; {***************************************************************************} var TempStr: string; begin Str(NumInt, TempStr); StrInt := TempStr; end; function StrIntLen(NumInt: longint; IntLen: integer): string; {***************************************************************************} var TempStr: string; begin Str(NumInt, TempStr); while length(TempStr) < IntLen do TempStr := ' ' + TempStr; StrIntLen := TempStr; end; function StrIntSig(NumInt: longint; IntLen: byte): string; {***************************************************************************} var Temp: string; begin Temp := StrIntZer(Abs(NumInt), IntLen - 1); if NumInt < 0 then Temp := '-' + Temp else Temp := '+' + Temp; StrIntSig := Temp; end; Function StrIntZer(NumIn: longint; NumLen: integer): string; {***************************************************************************} var TempStr: string; begin if NumIn >= 0 then begin Str(NumIn, TempStr); while length(TempStr) < NumLen do TempStr := '0' + TempStr; StrIntZer := TempStr; end else begin Str(-NumIn, TempStr); while length(TempStr) < NumLen do TempStr := '0' + TempStr; StrIntZer := '-' + TempStr; end; end; function StrReal(Number: real; Width, Decimals: integer): string; {***************************************************************************} var TempStr: string; begin Str(Number:Width:Decimals, TempStr); StrReal := TempStr; end; function StrSized(InStr: string; Size: byte): string; {***************************************************************************} var StrLen, alpha: byte; Temp: string; begin Temp := InStr; StrLen := length(InStr); if StrLen > Size then Temp := copy(InStr, 1, Size) else if StrLen < Size then for alpha := 1 to Size - StrLen do Temp := Temp + ' '; StrSized := Temp; end; function StrSizedLead(InStr: string; Size: byte): string; {***************************************************************************} var StrLen, alpha: byte; Temp: string; begin Temp := InStr; StrLen := length(InStr); if StrLen > Size then Temp := copy(InStr, 1, Size) else if StrLen < Size then for alpha := 1 to Size - StrLen do Temp := ' ' + Temp; StrSizedLead := Temp; end; Function StrLongInt(NumInt: longint): string; {***************************************************************************} var TempStr: string; begin str(NumInt, TempStr); StrLongInt := TempStr; end; Function StrPhone(InStr: string): string; {***************************************************************************} var Temp: string; begin Temp := InStr; Temp := StrStripNonNum(Temp); case length(Temp) of 7 : Temp := copy(Temp, 1, 3) + '-' + copy(Temp, 4, 4); 10: Temp := '(' + copy(Temp, 1, 3) + ')' + copy(Temp, 4, 3) + '-' + copy(Temp, 7, 4); 11: if Temp[1] = '1' then Temp := '' else Temp := '1-' + copy(Temp, 2, 3) + '-' + copy(Temp, 5, 3) + '-' + copy(Temp, 8, 4); else Temp := ''; end; StrPhone := Temp; end; Function StrStripNonNum(InStr: string): string; {***************************************************************************} var Index: byte; Temp: string; begin Temp := ''; for Index := 1 to length(InStr) do if InStr[Index] in ['0'..'9'] then Temp := Temp + InStr[Index]; StrStripNonNum := Temp; end; Function StrWrdZer(NumWrd: word; WrdLen: integer): string; {***************************************************************************} var TempStr: string; begin Str(NumWrd, TempStr); while length(TempStr) < WrdLen do TempStr := '0' + TempStr; StrWrdZer := TempStr; end; Function UpCaseFirstLetters(InStr: string): string; {***************************************************************************} var alpha: integer; OutStr: string; First: boolean; Letter: char; begin First := true; OutStr := ''; for alpha := 1 to length(InStr) do begin Letter := InStr[alpha]; if (Letter <> ' ') and First then begin Letter := UpCase(Letter); First := false; end; if Letter = ' ' then First := true; OutStr := OutStr + Letter; end; UpCaseFirstLetters := OutStr; end; function UpCaseStr(InStr: string): string; {***************************************************************************} var alpha: integer; begin for alpha := 1 to length(InStr) do InStr[alpha] := UpCase(InStr[alpha]); UpCaseStr := InStr; end; function WildCardFormat(FormatStr: string; InStr: string): boolean; {***************************************************************************} var Position, bravo: integer; TempWildCardFormat: boolean; LeadStr, ExtStr: string; LenFormatStr, LenInStr: integer; begin FormatStr := UpCaseStr(FormatStr); InStr := UpCaseStr(InStr); LenFormatStr := length(FormatStr); Position := 1; LeadStr := ''; while (FormatStr[Position] <> '*') and (Position <= LenFormatStr) and (FormatStr[Position] <> '.') do begin LeadStr := LeadStr + FormatStr[Position]; Inc(Position); end; ExtStr := ''; repeat Inc(Position); until (FormatStr[Position] = '.') or (Position >= LenFormatStr); Inc(Position); while (FormatStr[Position] <> '*') and (Position <= LenFormatStr) do begin ExtStr := ExtStr + FormatStr[Position]; Inc(Position); end; TempWildCardFormat := true; for Position := 1 to length(LeadStr) do begin if InStr[Position] <> LeadStr[Position] then TempWildCardFormat := false; end; LenInStr := length(InStr); Position := 0; repeat Inc(Position); if Position = 10 then TempWildCardFormat := false; until (InStr[Position] = '.') or (Position >= LenInStr); for bravo := 1 to length(ExtStr) do begin if InStr[Position+bravo] <> ExtStr[bravo] then TempWildCardFormat := false; end; WildCardFormat := TempWildCardFormat; end; {***************************************************************************} {***************************************************************************} {***************************************************************************} begin end.