⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _ststring.pas

📁 条码控件: 一维条码控件 二维条码控件 PDF417Barcode MaxiCodeBarcode
💻 PAS
📖 第 1 页 / 共 3 页
字号:
(* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is TurboPower SysTools
 *
 * The Initial Developer of the Original Code is
 * TurboPower Software
 *
 * Portions created by the Initial Developer are Copyright (C) 1996-2002
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** *)

{*********************************************************}
{*                  _STSTRING.PAS 3.00                   *}
{*********************************************************}

{$I STDEFINE.INC}
{$I STCOMDEF.INC}
unit _StString;

interface

uses
  ComObj, Classes, SysTools_TLB, StdVcl;

type
  TStString = class(TAutoObject, IStString)
   private   {Private declarations }
    FTokens     : IStStringList;
    FTokensList : TStringList;
    FIsLicensed : Boolean;
   public    {Public declarations }
    procedure Initialize; override;
    destructor Destroy; override;
   protected {Protected declarations }
    { IStString - Methods }
    function AddBackSlash(const DirName: WideString): WideString; safecall;
    function AsciiCount(const S, WordDelims, Quote: WideString): Integer; safecall;
    function AsciiPosition(N: Integer; const S, WordDelims, Quote: WideString; var Pos: Integer): WordBool; safecall;
    function BinaryB(B: Byte): WideString; safecall;
    function BinaryW(W: Integer): WideString; safecall;
    function BinaryL(L: Integer): WideString; safecall;
    function Center(const S: WideString; Len: Integer): WideString; safecall;
    function CenterCh(const S, C: WideString; Len: Integer): WideString; safecall;
    function CharCount(const S, C: WideString): Integer; safecall;
    function CharExists(const S, C: WideString): WordBool; safecall;
    function CharStr(const C: WideString; Len: Integer): WideString; safecall;
    function CleanPathName(const PathName: WideString): WideString; safecall;
    function Commaize(L: Integer): WideString; safecall;
    function CommaizeCh(L: Integer; const Ch: WideString): WideString; safecall;
    function CompString(const S1, S2: WideString): Integer; safecall;
    function CompUCString(const S1, S2: WideString): Integer; safecall;
    function ContainsOnly(const S, Chars: WideString; var BadPos: Integer): WordBool; safecall;
    function ContainsOtherThan(const S, Chars: WideString; var BadPos: Integer): WordBool; safecall;
    function CopyFromNthWord(const S, WordDelims, AWord: WideString; N: Integer; var SubString: WideString): WordBool; safecall;
    function CopyFromToWord(const S, WordDelims, Word1, Word2: WideString; N1, N2: Integer; var SubString: WideString): WordBool; safecall;
    function CopyLeft(const S: WideString; Len: Integer): WideString; safecall;
    function CopyMid(const S: WideString; First, Len: Integer): WideString; safecall;
    function CopyRight(const S: WideString; First: Integer): WideString; safecall;
    function CopyWithin(const S, Delimiter: WideString; Strip: WordBool): WideString; safecall;
    function DefaultExtension(const Name, Ext: WideString): WideString; safecall;
    function DeleteFromNthWord(const S, WordDelims, AWord: WideString; N: Integer; var SubString: WideString): WordBool; safecall;
    function DeleteFromToWord(const S, WordDelims, Word1, Word2: WideString; N1, N2: Integer; var SubString: WideString): WordBool; safecall;
    function DeleteWithin(const S, Delimeter: WideString): WideString; safecall;
    function Detab(const S: WideString; TabSize: Byte): WideString; safecall;
    function Entab(const S: WideString; TabSize: Byte): WideString; safecall;
    function Ext2Str(R: OleVariant; Width, Places: Byte): WideString; safecall;
    function ExtractAscii(N: Integer; const S, WordDelims, Quote: WideString): WideString; safecall;
    function ExtractTokens(const S, Delims, QuoteChar: WideString; AllowNulls: WordBool; out Tokens: IStStringList): Integer; safecall;
    function ExtractWord(N: Integer; const S, WordDelims: WideString): WideString; safecall;
    function Filter(const S, Filters: WideString): WideString; safecall;
    function FloatForm(const Mask: WideString; R: Double; L: Integer; const LtCurr, RtCurr, Sep, DecPt: WideString): WideString; safecall;
    function ForceExtension(const Name, Ext: WideString): WideString; safecall;
    function HasExtension(const Name: WideString; var DotPos: Integer): WordBool; safecall;
    function HexB(B: Byte): WideString; safecall;
    function HexW(W: Integer): WideString; safecall;
    function HexL(L: Integer): WideString; safecall;
    function IsChAlpha(const C: WideString): WordBool; safecall;
    function IsChAlphaNumeric(const C, Numbers: WideString): WordBool; safecall;
    function IsChNumeric(const C, Numbers: WideString): WordBool; safecall;
    function IsStrAlpha(const S: WideString): WordBool; safecall;
    function IsStrAlphaNumeric(const S, Numbers: WideString): WordBool; safecall;
    function IsStrNumeric(const S, Numbers: WideString): WordBool; safecall;
    function JustExtension(const Name: WideString): WideString; safecall;
    function JustFilename(const PathName: WideString): WideString; safecall;
    function JustName(const PathName: WideString): WideString; safecall;
    function JustPathname(const PathName: WideString): WideString; safecall;
    function KeepChars(const S, Chars: WideString): WideString; safecall;
    function LastString(const S, AString: WideString; var Position: Integer): WordBool; safecall;
    function LastWord(const S, WordDelims, AWord: WideString; var Position: Integer): WordBool; safecall;
    function LastWordAbs(const S, WordDelims: WideString; var Position: Integer): WordBool; safecall;
    function LeftPad(const S: WideString; Len: Integer): WideString; safecall;
    function LeftPadCh(const S, C: WideString; Len: Integer): WideString; safecall;
    function LeftTrimChars(const S, Chars: WideString): WideString; safecall;
    function Long2Str(L: Integer): WideString; safecall;
    function LongIntForm(const Mask: WideString; L: Integer; const LtCurr, RtCurr, Sep: WideString): WideString; safecall;
    function OctalB(B: Byte): WideString; safecall;
    function OctalW(W: Integer): WideString; safecall;
    function OctalL(L: Integer): WideString; safecall;
    function Pad(const S: WideString; Len: Integer): WideString; safecall;
    function PadCh(const S, C: WideString; Len: Integer): WideString; safecall;
    function Real2Str(R: Double; Width, Places: Byte): WideString; safecall;
    function RepeatString(const S: WideString; var Repetitions: Integer; MaxLen: Integer): WideString; safecall;
    function ReplaceWord(const S, WordDelims, OldWord, NewWord: WideString; N: Integer; var Replacements: Integer): WideString; safecall;
    function ReplaceWordAll(const S, WordDelims, OldWord, NewWord: WideString; var Replacements: Integer): WideString; safecall;
    function ReplaceString(const S, OldString, NewString: WideString; N: Integer; var Replacements: Integer): WideString; safecall;
    function ReplaceStringAll(const S, OldString, NewString: WideString; var Replacements: Integer): WideString; safecall;
    function RightTrimChars(const S, Chars: WideString): WideString; safecall;
    function Scramble(const S, Key: WideString): WideString; safecall;
    function Str2Ext(const S: WideString; var R: OleVariant): WordBool; safecall;
    function Str2Int16(const S: WideString; var I: Smallint): WordBool; safecall;
    function Str2Long(const S: WideString; var I: Integer): WordBool; safecall;
    function Str2Real(const S: WideString; var R: Double): WordBool; safecall;
    function Str2Word(const S: WideString; var W: Integer): WordBool; safecall;
    function StrChDelete(const S: WideString; Pos: Integer): WideString; safecall;
    function StrChInsert(const S, C: WideString; Pos: Integer): WideString; safecall;
    function StrChPos(const P, C: WideString; var Pos: Integer): WordBool; safecall;
    function StrStCopy(const S: WideString; Pos, Count: Integer): WideString; safecall;
    function StrStDelete(const S: WideString; Pos, Count: Integer): WideString; safecall;
    function StrStInsert(const S1, S2: WideString; Pos: Integer): WideString; safecall;
    function StrStPos(const P, S: WideString; var Pos: Integer): WordBool; safecall;
    function StrWithin(const S, SearchStr: WideString; Start: Integer; var Position: Integer): WordBool; safecall;
    function Substitute(const S, FromStr, ToStr: WideString): WideString; safecall;
    function Trim(const S: WideString): WideString; safecall;
    function TrimChars(const S, Chars: WideString): WideString; safecall;
    function TrimLead(const S: WideString): WideString; safecall;
    function TrimSpaces(const S: WideString): WideString; safecall;
    function TrimTrail(const S: WideString): WideString; safecall;
    function ValPrep(const S: WideString): WideString; safecall;
    function WordCount(const S, WordDelims: WideString): Integer; safecall;
    function WordPos(const S, WordDelims, AWord: WideString; N: Integer; var Position: Integer): WordBool; safecall;
    function WordPosition(N: Integer; const S, WordDelims: WideString; var Position: Integer): WordBool; safecall;
    procedure WordWrap(const InSt: WideString; var OutSt, Overlap: WideString; Margin: Integer; PadToMArgin: WordBool); safecall;
    function License(const Key: WideString): WordBool; safecall;
    function Soundex(const S: WideString): WideString; safecall;
  end;

implementation

uses ComServ, StStrL, StStrW, _StUtil {$IFDEF LICENSE}, ActiveX, StComLic {$ENDIF};

{ ********** TStString Interface ********************************************************* }
procedure TStString.Initialize;
begin
  inherited Initialize;
  FTokensList := TStringList.Create;
  FTokens := TStStringList.Create(FTokensList);
  {$IFDEF LICENSE}
  FIsLicensed := False;
  {$ELSE}
  FIsLicensed := True;
  {$ENDIF}
end;

destructor TStString.Destroy;
begin
  if Assigned (FTokensList) then
    FTokensList.Free;

  FTokens := nil;
  inherited Destroy;
end;

{ ********** TStString Methods *********************************************************** }
function TStString.AddBackSlash(const DirName: WideString): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.AddBackSlashW(DirName);
end;

function TStString.AsciiCount(const S, WordDelims,
  Quote: WideString): Integer;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.AsciiCountW(S, WordDelims, Quote[1])
end;

function TStString.AsciiPosition(N: Integer; const S, WordDelims,
  Quote: WideString; var Pos: Integer): WordBool;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.AsciiPositionW(Cardinal(N), S, WordDelims, Quote[1], Cardinal(Pos));
end;

function TStString.BinaryB(B: Byte): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.BinaryBW(B);
end;

function TStString.BinaryW(W: Integer): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.BinaryWW(W);
end;

function TStString.BinaryL(L: Integer): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.BinaryLW(Cardinal(L));
end;

function TStString.Center(const S: WideString; Len: Integer): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CenterW(S, Cardinal(Len));
end;

function TStString.CenterCh(const S, C: WideString;
  Len: Integer): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CenterChW(S, C[1], Cardinal(Len));
end;

function TStString.CharCount(const S, C: WideString): Integer;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CharCountW(S, C[1]);
end;

function TStString.CharExists(const S, C: WideString): WordBool;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CharExistsW(S, C[1]);
end;

function TStString.CharStr(const C: WideString; Len: Integer): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CharStrW(C[1], Cardinal(Len));
end;

function TStString.CleanPathName(const PathName: WideString): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CleanPathNameW(PathName);
end;

function TStString.Commaize(L: Integer): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CommaizeW(LongInt(L));
end;

function TStString.CommaizeCh(L: Integer;
  const Ch: WideString): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CommaizeChW(LongInt(L), Ch[1]);
end;

function TStString.CompString(const S1, S2: WideString): Integer;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CompStringW(S1, S2);
end;

function TStString.CompUCString(const S1, S2: WideString): Integer;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CompUCStringW(S1, S2);
end;

function TStString.ContainsOnly(const S, Chars: WideString;
  var BadPos: Integer): WordBool;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.ContainsOnlyW(S, Chars, Cardinal(BadPos));
end;

function TStString.ContainsOtherThan(const S, Chars: WideString;
  var BadPos: Integer): WordBool;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.ContainsOtherThanW(S, Chars, Cardinal(BadPos));
end;

function TStString.CopyFromNthWord(const S, WordDelims, AWord: WideString;
  N: Integer; var SubString: WideString): WordBool;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CopyFromNthWordW(S, WordDelims, AWord, Cardinal(N), SubString);
end;

function TStString.CopyFromToWord(const S, WordDelims, Word1,
  Word2: WideString; N1, N2: Integer; var SubString: WideString): WordBool;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CopyFromToWordW(S, WordDelims, Word1, Word2, Cardinal(N1), Cardinal(N2), SubString);
end;

function TStString.CopyLeft(const S: WideString; Len: Integer): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StStrW.CopyLeftW(S, Cardinal(Len));
end;

function TStString.CopyMid(const S: WideString; First,
  Len: Integer): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -