?? globalunit.pas
字號:
begin
LeftPad:= LeftPadCh(S, ' ', Len);
end;
//返回一個字符,取掉左邊的空格和控制字符
function TAccessString.TrimLead(const S : string) : string;
{-Return a string with leading white space removed}
{$IFDEF WIN32}
begin
Result:= TrimLeft(S);
end;
{$ELSE}
var
I : integer;
begin
{>>A2.01} Result:= S;
I := 1;
while (I <= Length(S)) and (S[I] <= ' ') do
Inc(I);
Dec(I);
{>>A 2.01}
if I > 0 then
Delete(Result, 1, I);
{<<A 2.01}
end;
{$ENDIF WIN32}
//返回一個字符,取掉右邊的空格和控制字符
function TAccessString.TrimTrail(const S : string) : string;
{-Return a string with trailing white space removed}
{$IFDEF WIN32}
begin
Result:= SysUtils.TrimRight(S);
end;
{$ELSE}
var
SLen : integer;
begin
{>>A 2.01}
Result:= S;
{<<A 2.01}
SLen:= length(S);
while ( SLen > 0) and (S[SLen] <= ' ') do
Dec(SLen);
SetLength(Result, SLen);
end;
{$ENDIF WIN32}
//計(jì)算一個String中的單詞(word)數(shù),單詞的分隔符號由WordDelims指定
function TAccessString.WordCount(const S : string; WordDelims : TChrSet) : longint;
{-Given a set of word delimiters, return number of words in S}
var
I : longint;
SLen: longint;
begin
Result:= 0;
I:= 1;
SLen:= length(S);
while I <= SLen do begin
{skip over delimiters}
while (I <= SLen) and (S[I] in WordDelims) do
Inc(I);
{if we're not beyond end of S, we're at the start of a word}
if I <= SLen then
Inc(Result);
{find the end of the current word}
while (I <= SLen) and not(S[I] in WordDelims) do
Inc(I);
end;
end;
//***************************************************************
//計(jì)算一個String中的第N個單詞,單詞的分隔符號由WordDelims指定 *
//***************************************************************
function TAccessString.ExtractWord(N : longint; const S : string; WordDelims : TChrSet) : string;
{-Given a set of word delimiters, return the N'th word in S}
var
I, Count: longint;
Len : longint;
SLen : longint;
begin
Count:= 0;
I:= 1;
Len:= 0;
ExtractWord:= EmptyStr;
SLen:= length(S);
while (I <= SLen) and (Count <> N) do begin
{skip over delimiters}
while (I <= SLen) and (S[I] in WordDelims) do
Inc(I);
{if we're not beyond end of S, we're at the start of a word}
if I <= SLen then
Inc(Count);
{find the end of the current word}
while (I <= SLen) and not(S[I] in WordDelims) do begin
{if this is the N'th word, add the I'th character to Tmp}
if Count = N then begin
Inc(Len);
{$IFDEF WIN32}
SetLength(Result, Len);
Result[Len] := S[I];
{$ELSE}
Result[0] := Char(Len);
Result[Len] := S[I];
{$ENDIF}
end;
Inc(I);
end;
end;
end;
//***************************************************************
//清除一個字符串中指定的某一字符,'abc','b'--->'ac' *
//***************************************************************
{>>A 2.01}
function TAccessString.RemoveCharacter( const S: string; C: char ): string;
{- Return a string, contains no C chars }
var
Idx: word;
begin
Result:= NullString;
for Idx:= 1 to length(S) do
if S[Idx]<>C then Result:= Result + S[Idx];
end;
{<<A 2.01}
//***************************************************************
//清除一個字符串中多個空格,只流一個空格,'abc d' ->'abc d' *
//***************************************************************
function TAccessString.CompactSpaces( S : string ):string;
{- return a string with all white spaces removed }
var
P : word;
begin
S:= Trim( S );
if length(S)>0 then
begin
for P:=1 to length(S)-1 do
if (S[P]=' ') and ( (S[P+1]=' ') or
( (P>1) and (S[P-1]=' ') ) ) then
while( (S[P-1]=' ') or (S[P+1]=' ')) do
delete( S, P, 1 );
end; { if }
Result:= S;
end; { CompactSpaces }
//***************************************************************
//清除一個字符串中所有的空格 *
//***************************************************************
function TAccessString.RemoveSpaces( S : string ): string;
{- Return a string, contains no space chars }
begin
Result:= RemoveCharacter(S, ' ');
end; { RemoveSpaces }
//***************************************************************
//把一個數(shù)字轉(zhuǎn)換為右邊用Ch填充為Len長字符串:123,0,3-->'123000' *
//***************************************************************
function TAccessString.digiPadCh( D: longint; Ch : Char; Len : Byte) : string; {*}
{-Return a string right-padded to length len with ch}
begin
digiPadCh:= PadCh( long2str( D ), Ch, Len );
end;
//***************************************************************
//把一個數(shù)字轉(zhuǎn)換為右邊用空格填充為Len長字符串:123,3-->'123 ' *
//***************************************************************
function TAccessString.digiPad( D: longint; Len : Byte) : string; {*}
{-Return a string right-padded to length len with blanks}
begin
digiPad:= PadCh( long2str( D ), ' ', Len );
end;
//***************************************************************
//把一個數(shù)字轉(zhuǎn)換為左邊用Ch填充為Len長字符串:123,0,3-->'000123' *
//***************************************************************
function TAccessString.digiLeftPadCh( D: longint; Ch : Char; Len : Byte) : string;
{-Return a string left-padded to length len with ch}
begin
digiLeftPadCh:= LeftPadCh( long2str( D ), Ch, Len );
end;
//***************************************************************
//把一個數(shù)字轉(zhuǎn)換為左邊用空格填充為Len長字符串:123,,3-->' 123'*
//***************************************************************
function TAccessString.digiLeftPad( D: longint; Len : Byte) : string; {*}
{-Return a string left-padded to length len with blanks}
begin
digiLeftPad:= LeftPadCh( long2str( D ), ' ', Len );
end;
//***************************************************************
//返回一個pathname中的盤符 *
//***************************************************************
function TAccessString.JustDriveName( FName : string ):char;
begin
FName:= Trim( FName );
if FName[2]=':' then Result:= FName[1] else
Result:= #0;
end;
//***************************************************************
//返回一個pathname中的文件名除取擴(kuò)展名部分 *
//***************************************************************
function TAccessString.JustMainFileName( FName : string ):string;
{- return just a part of filename before point }
var
PointPos : word;
begin
PointPos:= pos( '.', FName );
if PointPos=0 then
Result:= Global.FAccessFile.JustFileName( FName )
else
begin
FName:= Global.FAccessFile.JustFileName(FName);
PointPos:= pos('.',FName);
Result:= Copy( FName, 1, PointPos-1 );
end; { if else }
end; { JustMainFileName }
//***************************************************************
//清除一個pathname中的'\' *
//***************************************************************
{>>A 1.11}
function TAccessString.RemoveBackSlash( P : string ): string;
begin
while (length(P)>0) and (P[length(P)]='\') do
delete( P, length(P), 1 );
Result:= P;
end; { RemoveBackSlash }
//***************************************************************
//返回String中左邊Len長度的字符串 *
//***************************************************************
function TAccessString.TruncLine( S : string; Len : byte ): string;
begin
Result:= S;
if length(Result) > Len then
SetLength(Result, Len);
end; { TruncLine }
//***************************************************************
//返回String中右邊Len長度的字符串 *
//***************************************************************
function TAccessString.TruncLineRt( S : string; Len : byte ): string;
begin
if length( S ) > Len then
begin
delete( S, 1, length(S)-Len );
TruncLineRt:= S;
end
else
TruncLineRt:= S;
end; { TruncLine }
//***************************************************************
//比較兩個String是否相等,大小寫敏感 *
//***************************************************************
function TAccessString.StringsIsEqual( S1, S2 : string ): boolean;
{$IFNDEF WIN32}assembler;{$ENDIF WIN32}
{$IFDEF WIN32}
begin
Result:= ( CompareStr(S1, S2) = 0);
{$ELSE WIN32}
asm
push DS
xor BX, BX { assume failure in temp result }
les DI, S2 { ES:[DI] points to S2[0] }
lds SI, S1 { DS:[SI] points to S1[0] }
mov AH, DS:[SI] { length of S1 in AH }
cmp AH, ES:[DI] { compare lengths of S1 and S2 }
jne @@Done { if not equal then exit with False }
xor CX, CX
mov CL, AH { number of chars to compare in CX }
inc DI { ES:[DI] now points to S2[1] }
inc SI { DS:[SI] now points to S1[1] }
repe cmpsb { compare until NO MATCH or CX=0 }
ja @@Done { if no match then exit with False }
mov BX, 01 { match, returns True }
@@Done :
pop DS
mov AX, BX { set result from temp store }
{$ENDIF WIN32}
end;
{/////////////////////////////////////////////////////////////////////////////}
//***************************************************************
//使一個String的第一個字符變成大寫 *
//***************************************************************
function TAccessString.FormAsName(S:string): string; {*}
{-Make first letter in string as uppercase }
begin
S:= ANSIlowerCase( S );
S[1]:= ANSIupperCase( S[1] )[1];
Result:= S;
end; { FormAsName }
//***************************************************************
//使一個String的每一個單詞的第一個字符變成大寫 *
//***************************************************************
function TAccessString.FormAmericanString(S:string) : string; {*}
{-Make first letters in line as uppercase }
var P : byte;
begin
S[1]:= ANSIupperCase( S[1] )[1];
for P:=1 to length(S)-1 do
if (S[P]=' ') and (S[P+1]<>' ') then S[P+1]:= ANSIupperCase(S[P+1])[1];
Result:= S;
end; { FormAmericanString }
{>>A 2.01}
//***************************************************************
//轉(zhuǎn)換一個String to 數(shù)字 *
//***************************************************************
function TAccessString. nxStrToInt(const S: string): longint;
begin
if trim(S) = EmptyStr then Result:= 0
else Result:= StrToInt(S);
end; { nxStrToInt }
//***************************************************************
//判斷一個String是否為NULL *
//***************************************************************
function TAccessString. StrIsNull(const S: string): boolean;
begin
Result:= (length(trim(S))<=0);
end; { StrIsNull }
{<<A 2.01}
//***************************************************************
//統(tǒng)計(jì)一個String中某一字符的個數(shù) *
//***************************************************************
{>>A 2.02}
function TAccessString. CharCount(C: char; const S: string): integer;
var
Idx: integer;
begin
Result:= 0;
for Idx:= 1 to length(S) do
inc(Result, byte( S[Idx]=C ));
end; { CharCount }
//***************************************************************
//用一個字符替換String中另一字符 *
//***************************************************************
procedure TAccessString.ReplaceChar(SrcChar, DstChar: char; var S: string);
{- replaces all occurencies of SrcChar in string S by DstChar }
var
I: integer;
begin
for I:= 1 to length(S) do
if S[I] = SrcChar then
S[I]:= DstChar;
end; { ReplaceChar }
//***************************************************************
//取一個字符串中雙引號中間的字符串,
//如果沒有雙引號,則取全集
//如果有一個雙引號,則取雙引號右邊的字符串 *
//***************************************************************
function TAccessString. GetQuotedString(const S: string): string;
var
QPos: {$IFDEF DELPHI3}longint{$ELSE}word{$ENDIF};
begin
QPos:= pos(DoubleQuote, S);
if QPos<=0 then
begin
Result:= S;
Exit;
end; { if }
Result:= S;
delete(Result, 1, QPos+1);
QPos:= pos(DoubleQuote, Result);
if QPos>0 then
Result:= copy(Result, 1, QPos-1);
end; { GetQuotedString }
//***************************************************************
//轉(zhuǎn)換十六進(jìn)制的字符串為一個數(shù)字
//***************************************************************
function TAccessString. HexToInt(const H: string; Digits: integer; var I: longint): boolean;
{- Converts a hexadecimal string to long integer. Digits determines how
much digits in a string must be used during conversion. Returns False if
empty string passed or non-hex characters encountered. If error occurs,
I variable does not changes it's value. In case of success returns True
and decimal value in I variable. }
var
Idx: integer;
L: longint;
H2B: byte;
Pwr: byte;
function HexPower(Signer: integer): longint;
var
HxIdx: integer;
begin
Result:= 1;
if Signer=0 then
Exit;
Result:= 1;
for HxIdx:= 1 to Signer do
Result:= Result * 16;
end; { HexPower }
begin
Result:= False;
L:= 0;
for Idx:= 1 to length(H) do
if pos(UpCase(H[Idx]), HEXdigits) = 0 then Exit;
if Digits>8 then
Exit;
Pwr:= 0;
for Idx:= length(H) downto 1 do
begin
for H2B:= 0 to $F do
if HEXdigits[H2B] = UpCase(H[Idx]) then
begin
L:= L + HexPower(Pwr) * H2B;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -