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

📄 ststrs.pas

📁 条码控件: 一维条码控件 二维条码控件 PDF417Barcode MaxiCodeBarcode
💻 PAS
📖 第 1 页 / 共 5 页
字号:
(* ***** 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 ***** *)

{*********************************************************}
{* SysTools: StStrS.pas 4.03                             *}
{*********************************************************}
{* SysTools: Short string routines                       *}
{*********************************************************}

{$I StDefine.inc}

unit StStrS;

interface

uses
  Windows,
  Classes,
  SysUtils,
  StConst,
  StBase;

  {-------- Numeric conversion -----------}

function HexBS(B : Byte) : ShortString;
  {-Return the hex string for a byte.}

function HexWS(W : Word) : ShortString;
  {-Return the hex string for a word.}

function HexLS(L : LongInt) : ShortString;
  {-Return the hex string for a long integer.}

function HexPtrS(P : Pointer) : ShortString;
  {-Return the hex string for a pointer.}

function BinaryBS(B : Byte) : ShortString;
  {-Return a binary string for a byte.}

function BinaryWS(W : Word) : ShortString;
  {-Return the binary string for a word.}

function BinaryLS(L : LongInt) : ShortString;
  {-Return the binary string for a long integer.}

function OctalBS(B : Byte) : ShortString;
  {-Return an octal string for a byte.}

function OctalWS(W : Word) : ShortString;
  {-Return an octal string for a word.}

function OctalLS(L : LongInt) : ShortString;
  {-Return an octal string for a long integer.}

function Str2Int16S(const S : ShortString; var I : SmallInt) : Boolean;
  {-Convert a string to an SmallInt.}

function Str2WordS(const S : ShortString; var I : Word) : Boolean;
  {-Convert a string to a word.}

function Str2LongS(const S : ShortString; var I : LongInt) : Boolean;
  {-Convert a string to a long integer.}

{$IFDEF VER93}                                                         
function Str2RealS(const S : ShortString; var R : Double) : Boolean;
{$ELSE}                                                                
  {-Convert a string to a real.}
function Str2RealS(const S : ShortString; var R : Real) : Boolean;     
{$ENDIF}                                                               

function Str2ExtS(const S : ShortString; var R : Extended) : Boolean;
  {-Convert a string to an extended.}

function Long2StrS(L : LongInt) : ShortString;
  {-Convert an integer type to a string.}

function Real2StrS(R : Double; Width : Byte; Places : ShortInt) : ShortString;
  {-Convert a real to a string.}

function Ext2StrS(R : Extended; Width : Byte; Places : ShortInt) : ShortString;
  {-Convert an extended to a string.}

function ValPrepS(const S : ShortString) : ShortString;
  {-Prepares a string for calling Val.}


  {-------- General purpose string manipulation --------}

function CharStrS(C : AnsiChar; Len : Cardinal) : ShortString;
  {-Return a string filled with the specified character.}

function PadChS(const S : ShortString; C : AnsiChar; Len : Cardinal) : ShortString;
  {-Pad a string on the right with a specified character.}

function PadS(const S : ShortString; Len : Cardinal) : ShortString;
  {-Pad a string on the right with spaces.}

function LeftPadChS(const S : ShortString; C : AnsiChar; Len : Cardinal) : ShortString;
  {-Pad a string on the left with a specified character.}

function LeftPadS(const S : ShortString; Len : Cardinal) : ShortString;
  {-Pad a string on the left with spaces.}

function TrimLeadS(const S : ShortString) : ShortString;
  {-Return a string with leading white space removed.}

function TrimTrailS(const S : ShortString) : ShortString;
  {-Return a string with trailing white space removed.}

function TrimS(const S : ShortString) : ShortString;
  {-Return a string with leading and trailing white space removed.}

function TrimSpacesS(const S : ShortString) : ShortString;
  {-Return a string with leading and trailing spaces removed.}

function CenterChS(const S : ShortString; C : AnsiChar; Len : Cardinal) : ShortString;
  {-Pad a string on the left and right with a specified character.}

function CenterS(const S : ShortString; Len : Cardinal) : ShortString;
  {-Pad a string on the left and right with spaces.}

function EntabS(const S : ShortString; TabSize : Byte) : ShortString;
  {-Convert blanks in a string to tabs.}

function DetabS(const S : ShortString; TabSize : Byte) : ShortString;
  {-Expand tabs in a string to blanks.}

function ScrambleS(const S, Key : ShortString) : ShortString;
  {-Encrypt / Decrypt string with enhanced XOR encryption.}

function SubstituteS(const S, FromStr, ToStr : ShortString) : ShortString;
  {-Map the characters found in FromStr to the corresponding ones in ToStr.}

function FilterS(const S, Filters : ShortString) : ShortString;
  {-Remove characters from a string. The characters to remove are specified in
    ChSet.}

  {--------------- Word / Char manipulation -------------------------}

function CharExistsS(const S : ShortString; C : AnsiChar) : Boolean;
  {-Determines whether a given character exists in a string. }

function CharCountS(const S : ShortString; C : AnsiChar) : Byte;
  {-Count the number of a given character in a string. }

function WordCountS(const S, WordDelims : ShortString) : Cardinal;
  {-Given an array of word delimiters, return the number of words in a string.}

function WordPositionS(N : Cardinal; const S, WordDelims : ShortString;
                      var Pos : Cardinal) : Boolean;
  {-Given an array of word delimiters, set Pos to the start position of the
    N'th word in a string.  Result indicates success/failure.}

function ExtractWordS(N : Cardinal; const S, WordDelims : ShortString) : ShortString;
  {-Given an array of word delimiters, return the N'th word in a string.}

function AsciiCountS(const S, WordDelims : ShortString; Quote : AnsiChar) : Cardinal;
  {-Return the number of words in a string.}

function AsciiPositionS(N : Cardinal; const S, WordDelims : ShortString;
                        Quote : AnsiChar; var Pos : Cardinal) : Boolean;
  {-Return the position of the N'th word in a string.}

function ExtractAsciiS(N : Cardinal; const S, WordDelims : ShortString;
                       Quote : AnsiChar) : ShortString;
  {-Given an array of word delimiters, return the N'th word in a string. Any
    text within Quote characters is counted as one word.}

procedure WordWrapS(const InSt : ShortString; var OutSt, Overlap : ShortString;
                    Margin : Cardinal; PadToMargin : Boolean);
  {-Wrap a text string at a specified margin.}

  {--------------- String comparison and searching -----------------}
function CompStringS(const S1, S2 : ShortString) : Integer;
  {-Compare two strings.}

function CompUCStringS(const S1, S2 : ShortString) : Integer;
  {-Compare two strings. This compare is not case sensitive.}

function SoundexS(const S : ShortString) : ShortString;
  {-Return 4 character soundex of an input string.}

function MakeLetterSetS(const S : ShortString) : Longint;
  {-Return a bit-mapped long storing the individual letters contained in S.}

procedure BMMakeTableS(const MatchString : ShortString; var BT : BTable);
  {-Build a Boyer-Moore link table}

function BMSearchS(var Buffer; BufLength : Cardinal; var BT : BTable;
                  const MatchString : ShortString ; var Pos : Cardinal) : Boolean;
  {-Use the Boyer-Moore search method to search a buffer for a string.}

function BMSearchUCS(var Buffer; BufLength : Cardinal; var BT : BTable;
                    const MatchString : ShortString ; var Pos : Cardinal) : Boolean;
  {-Use the Boyer-Moore search method to search a buffer for a string. This
    search is not case sensitive.}

  {--------------- DOS pathname parsing -----------------}

function DefaultExtensionS(const Name, Ext : ShortString) : ShortString;
  {-Return a file name with a default extension attached.}

function ForceExtensionS(const Name, Ext : ShortString) : ShortString;
  {-Force the specified extension onto the file name.}

function JustFilenameS(const PathName : ShortString) : ShortString;
  {-Return just the filename and extension of a pathname.}

function JustNameS(const PathName : ShortString) : ShortString;
  {-Return just the filename (no extension, path, or drive) of a pathname.}

function JustExtensionS(const Name : ShortString) : ShortString;
  {-Return just the extension of a pathname.}

function JustPathnameS(const PathName : ShortString) : ShortString;
  {-Return just the drive and directory portion of a pathname.}

function AddBackSlashS(const DirName : ShortString) : ShortString;
  {-Add a default backslash to a directory name.}

function CleanPathNameS(const PathName : ShortString) : ShortString;
  {-Return a pathname cleaned up as DOS does it.}

function HasExtensionS(const Name : ShortString; var DotPos : Cardinal) : Boolean;
  {-Determine if a pathname contains an extension and, if so, return the
    position of the dot in front of the extension.}

  {------------------ Formatting routines --------------------}

function CommaizeS(L : LongInt) : ShortString;
  {-Convert a long integer to a string with commas.}

function CommaizeChS(L : Longint; Ch : AnsiChar) : ShortString;
  {-Convert a long integer to a string with Ch in comma positions.}

function FloatFormS(const Mask : ShortString ; R : TstFloat ; const LtCurr,
                    RtCurr : ShortString ; Sep, DecPt : AnsiChar) : ShortString;
  {-Return a formatted string with digits from R merged into mask.}

function LongIntFormS(const Mask : ShortString ; L : LongInt ; const LtCurr,
                     RtCurr : ShortString ; Sep : AnsiChar) : ShortString;
  {-Return a formatted string with digits from L merged into mask.}

function StrChPosS(const P : ShortString; C : AnsiChar; var Pos : Cardinal) : Boolean;
  {-Return the position of a specified character within a string.}

function StrStPosS(const P, S : ShortString; var Pos : Cardinal) : Boolean;
  {-Return the position of a specified substring within a string.}

function StrStCopyS(const S : ShortString; Pos, Count : Cardinal) : ShortString;
  {-Copy characters at a specified position in a string.}

function StrChInsertS(const S : ShortString; C : AnsiChar; Pos : Cardinal) : ShortString;
  {-Insert a character into a string at a specified position.}

function StrStInsertS(const S1, S2 : ShortString; Pos : Cardinal) : ShortString;
  {-Insert a string into another string at a specified position.}

function StrChDeleteS(const S : ShortString; Pos : Cardinal) : ShortString;
  {-Delete the character at a specified position in a string.}

function StrStDeleteS(const S : ShortString; Pos, Count : Cardinal) : ShortString;
  {-Delete characters at a specified position in a string.}


{--------------------------  New Functions -----------------------------------}

function ContainsOnlyS(const S, Chars : ShortString;
                       var BadPos : Cardinal) : Boolean;

function ContainsOtherThanS(const S, Chars : ShortString;
                            var BadPos : Cardinal) : Boolean;

function CopyLeftS(const S : ShortString; Len : Cardinal) : ShortString;
  {-Return the left Len characters of a string}

function CopyMidS(const S : ShortString; First, Len : Cardinal) : ShortString;
  {-Return the mid part of a string}

function CopyRightS(const S : ShortString; First : Cardinal) : ShortString;
  {-Return the right Len characters of a string}

function CopyRightAbsS(const S : ShortString; NumChars : Cardinal) : ShortString;
  {-Return NumChar characters starting from end}

function CopyFromNthWordS(const S, WordDelims : ShortString;
                          const AWord : ShortString; N : Cardinal;     {!!.02}
                          var SubString : ShortString) : Boolean;

function DeleteFromNthWordS(const S, WordDelims : ShortString;
                            AWord : ShortString; N : Cardinal;
                            var SubString : ShortString) : Boolean;

function CopyFromToWordS(const S, WordDelims, Word1, Word2 : ShortString;
                         N1, N2 : Cardinal;
                         var SubString : ShortString) : Boolean;

function DeleteFromToWordS(const S, WordDelims, Word1, Word2 : ShortString;
                           N1, N2 : Cardinal;
                           var SubString : ShortString) : Boolean;

function CopyWithinS(const S, Delimiter : ShortString;
                     Strip : Boolean) : ShortString;

function DeleteWithinS(const S, Delimiter : ShortString) : ShortString;

function ExtractTokensS(const S, Delims  : ShortString;
                              QuoteChar  : AnsiChar;
                              AllowNulls : Boolean;
                              Tokens     : TStrings) : Cardinal;

function IsChAlphaS(C : Char) : Boolean;
 {-Returns true if Ch is an alpha}

function IsChNumericS(C : Char; const Numbers : ShortString) : Boolean;
 {-Returns true if Ch in numeric set}

function IsChAlphaNumericS(C : Char; const Numbers : ShortString) : Boolean;
  {-Returns true if Ch is an alpha or numeric}

function IsStrAlphaS(const S : Shortstring) : Boolean;
  {-Returns true if all characters in string are an alpha}

function IsStrNumericS(const S, Numbers : ShortString) : Boolean;
  {-Returns true if all characters in string are in numeric set}

function IsStrAlphaNumericS(const S, Numbers : ShortString) : Boolean;
  {-Returns true if all characters in string are alpha or numeric}

function LastWordS(const S, WordDelims, AWord : ShortString;
                   var Position : Cardinal) : Boolean;
  {-returns the position in a string of the last instance of a given word}

function LastWordAbsS(const S, WordDelims : ShortString;
                      var Position : Cardinal) : Boolean;
  {-returns the position in a string of the last word}

function LastStringS(const S, AString : ShortString;
                     var Position : Cardinal) : Boolean;
  {-returns the position in a string of the last instance of a given string}

function LeftTrimCharsS(const S, Chars : ShortString) : ShortString;
  {-strips given characters from the beginning of a string}

function KeepCharsS(const S, Chars : ShortString) : ShortString;
  {-returns a string containing only those characters in a given set}

function RepeatStringS(const RepeatString : ShortString;
                       var Repetitions : Cardinal;
                       MaxLen : Cardinal) : ShortString;
  {-creates a string of up to Repetition instances of a string}

function ReplaceStringS(const S, OldString, NewString : ShortString;
                        N : Cardinal;
                        var Replacements : Cardinal) : ShortString;
  {-replaces a substring with up to Replacements instances of a string}

function ReplaceStringAllS(const S, OldString, NewString : ShortString;
                        var Replacements : Cardinal) : ShortString;
  {-replaces all instances of a substring with one or more instances of a string}

function ReplaceWordS(const S, WordDelims, OldWord, NewWord : ShortString;
                      N : Cardinal;
                      var Replacements : Cardinal) : ShortString;
  {-replaces a given word with one or more instances of a string}

function ReplaceWordAllS(const S, WordDelims, OldWord, NewWord : ShortString;
                         var Replacements : Cardinal) : ShortString;
  {-replaces all instances of a word with one or more instances of a string}

function RightTrimCharsS(const S, Chars : ShortString) : ShortString;
  {-removes those characters at the end of a string contained in a set of characters}

function StrWithinS(const S, SearchStr : ShortString;
                    Start : Cardinal;
                    var Position : Cardinal) : boolean;
  {-finds the position of a substring within a string starting at a given point}

function TrimCharsS(const S, Chars : ShortString) : ShortString;
  {-removes trailing and leading characters defined by a string from a string}

function WordPosS(const S, WordDelims, AWord : ShortString;
                  N : Cardinal; var Position : Cardinal) : Boolean;
  {-returns the Nth instance of a word within a string}


implementation


  {-------- Numeric conversion -----------}

function HexBS(B : Byte) : ShortString;
  {-Return the hex string for a byte.}

⌨️ 快捷键说明

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