unit LibStrs;
interface
uses Classes, Windows;
function PadL(const str: String; others: array of integer): String;
function PadR(const str: String; others: array of integer): String;
function Center(xStr:string; xLen:integer):string;
function GetToken(AString, SepStr: string; TokenNum: Integer): string; // Τ丁筳才腹﹃い﹃ ...
function NumToken(AString, SepStr: string): Integer; // Τ丁筳才腹﹃羆计 ...
function ReplaceToken(AString, SepStr: string; TokenNum: Integer; xNew: string): string; // Token ﹃ ...
function CutToken(var sString: string; const sDelim: string): string;
function FindToken(xString,SepStr,xToken:string):Integer; // т Token ┮
function ReplaceSubStr(xSource,xOld,xNew:string):string; // ﹃
function KillSubStr(xSource,xStr:string):string;
function ZeroATfirst(xValue, xLen: Integer): string;
function Replicate(xSource:string;xTimes:integer):string; // 硈尿狡籹﹃
function Space(xTimes:integer):string; // 眔琿フ﹃
function RightStr(Const Str: String; Size: Word): String;//﹃
function IIF(Check:Boolean; aValue1,aValue2: Variant):Variant;
function SlashSep(const Path, S: string): string;
function ExtraPos(xSubStr,xSource:string;xNumber:integer):integer; // 肚材碭﹃觃
function OnlyFileName(aFileName:String):String;// 奔 Path ㎝ Ext 郎
function TransDateIn(Value: string): TDateTime ;
function DateToString( xDate: TDateTime; xType: Integer; xDelim: string ):string ;
function StringToDate( xDate: string ; xType: Integer; xDelim: string ):TDateTime ;
function CheckCompanyNo(const Value : string ) : Boolean ; // 参絪腹
function CheckPersonNo (const Value : string ) : Boolean; // 浪琩ōだ靡腹絏琌タ絋 Jachu
function CheckDate (const Value : string ) : Boolean; // 浪琩ら戳琌猭
function GetMonthName(const Value:string):string; // 眔璣ゅる嘿
function WhatADate(const Value:TDateTime):string; // 肚 DEC.14 1998 Α
function InGroup(xGroup,xGroupList: string): Boolean;
function RemoveXSC( xStr : string) : string; //J р asc ┪ desc 奔 р フ奔
procedure StringToStrList(input: string; delimiter: string; output: TStringList);
function IsVarEmptyOrNull(xVariant: Variant): Boolean;
function CountDate(xSourceDate:variant;xKind:string;xMove:integer):String; //衡ら戳ㄧ计
function SwapStr(xString, xOldSplit, xNewSplit: String): String; // 蠢传疭﹚﹃
function Store(xValue: Variant; xVariant: Variant; xFieldList: array of Integer): Variant;
Function SetNetDir(xAlias: string): Boolean; // 砞﹚netdir
function Changedate( xDate: string ; xType: integer; xDelim: string ):String ;
function AddAliasName(xSource,xField,xAlias:string):string;
function NumberToEnglish(Value:Double):string; // 计锣璣ゅ
function ReplacePageNo(xSource,xOld:string):string; //北 PAGE CURPAGE OF TOTPAGE
function JosRound(xValue:double;xDecimal:integer):double; //彼き
function AddTstrings(x:TstringList;var F:TextFile):integer; //Vicky 1999.07.22
implementation
uses SysUtils, Dialogs, LibSys,DBtables;
function PadL(const str: String; others: array of integer): String;//オ恶じ
var
nAlen: Integer;
nLen1, nLen2, nLen: integer;
cFiller: char;
StrFill: String;
kk: integer;
begin
nAlen := High(others)+1;
nLen1 := Length(str);
nLen2 := others[0];
if nLen1 >= nLen2 then
begin
Result := str;
exit;
end;
if nAlen > 1 then cFiller := chr(others[1])
else cFiller := ' ';
nLen := nLen2-nLen1;
SetLength(StrFill, nLen);
for kk := 1 to nLen do
strFill[kk] := cFiller;
Result := Format('%s%s', [strFill, str]);
end;
function PadR(const str: String; others: array of integer): String;// 恶じ
var
nAlen: Integer;
nLen1, nLen2, nLen: integer;
cFiller: char;
StrFill: String;
kk: integer;
begin
nAlen := High(others)+1;
nLen1 := Length(str);
nLen2 := others[0];
if nLen1 >= nLen2 then
begin
Result := str;
exit;
end;
if nAlen > 1 then cFiller := chr(others[1])
else cFiller := ' ';
nLen := nLen2-nLen1;
SetLength(StrFill, nLen);
for kk := 1 to nLen do
strFill[kk] := cFiller;
Result := Format('%s%s', [str,strFill]);
end;
//Τ丁筳才腹﹃い﹃
function GetToken(AString, SepStr: string; TokenNum: Integer): string;
var
Token: string;
StrLen: Integer;
SepLen: Integer;
TNum: Integer;
TEnd: Integer;
begin
StrLen := Length(AString);
SepLen := Length(SepStr);
TNum := 1;
TEnd := StrLen;
while ((TNum <= TokenNum) and (TEnd <> 0)) do
begin
TEnd := AnsiPos(SepStr, AString);
if TEnd <> 0 then
begin
Token := Copy(AString, 1, TEnd - 1);
Delete(AString, 1, TEnd + SepLen - 1);
Inc(TNum);
end
else
begin
Token := AString;
end;
end;
if TNum >= TokenNum then Result := Token
else Result := '';
end;
//Τ丁筳才腹﹃羆计
function NumToken(AString, SepStr: string): Integer;
var
RChar: Char;
StrLen: Integer;
TNum: Integer;
TEnd: Integer;
begin
if SepStr = '#' then RChar := '*' else RChar := '#';
StrLen := Length(AString);
TNum := 0;
TEnd := StrLen;
while TEnd <> 0 do
begin
Inc(TNum);
TEnd := AnsiPos(SepStr, AString);
if TEnd <> 0 then AString[TEnd] := RChar;
end;
Result := TNum;
end;
// т Token ┮
function FindToken(xString,SepStr,xToken:string):Integer;
var
i:integer;
begin
Result:=0;
for i:=1 to NumToken(xString,SepStr) do
if GetToken(xString,SepStr,i)=xToken then
begin
Result:=i;
Break;
end;
end;
// Token ﹃ ...
function ReplaceToken(AString, SepStr: string; TokenNum: Integer; xNew: string): string;
var
I: Integer;
mMaxNum: Integer;
begin
Result := '';
mMaxNum := NumToken(AString, SepStr);
if TokenNum > mMaxNum then
mMaxNum := TokenNum;
for I := 1 to mMaxNum do
begin
if I > NumToken(AString, SepStr) then
AString := AString + SepStr;
if I = TokenNum then
Result := Result + xNew + SepStr
else
Result := Result + GetToken(AString, SepStr, I) + SepStr;
end;
if Result <> '' then
Result := Copy(Result, 1, Length(Result) - Length(SepStr)); // 搭だ筳才腹
end;
// Kill SubStrings in String
function KillSubStr(xSource,xStr:string):string;
var
mLeft,mRight:string;
mPos:integer;
begin
while Pos(xStr,xSource)>0 do
begin
mPos:=Pos(xStr,xSource);
mLeft:=Copy(xSource,1,mPos-1);
mRight:=Copy(xSource,mPos+Length(xStr),Length(xSource));
xSource:=mLeft+mRight;
end;
Result:=xSource;
end;
{******************************************