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

📄 u_stringpublicpack.pas

📁 软件功能:下载一个网站上所有的彩铃! 铃声下载完后
💻 PAS
📖 第 1 页 / 共 2 页
字号:
Unit U_StringPublicPack;

Interface

Uses
  Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Menus,
  Dialogs,Buttons,StdCtrls,Mask,ExtCtrls,ADODB,QControls,ComCtrls,IniFiles,CheckLst,
  ShellAPI,DateUtils,ComObj,Math,DBGrids,U_RecordStruct;

  //计算一个字符串的加法算法
  Function Add(Str:String):String;
  //计算一个字符串的减法算法
  Function Sub(Str:String):String;
  //计算一个字符串的乘法算法
  Function Mul(Str:String):String;
  //计算一个字符串的除法算法
  Function Divi(Str:String):String;
  //一个多项式的计算算法
  Function ComputeStr(Str:String):String;
  //获取字符串的第一个数据
  Function GetFirst(Str:String):String;
  //获取字符串的最后一个数据
  Function GetLast(Str:String):String;
  //获取一个字符串的值
  Function GetValue(Str:String):String;
  //获取当天的星期
  Function GetWeekOfDay(CurrentDate:TDate):String;
  //设置字符对齐方式(以PlaceChar补位)
  Function SetStringWidth(Str,PlaceChar:String;Width:Integer;Option{为1是左对齐为2是右对齐}:Integer):String;
  //字符多种替换过程
  Function MulReplace(Info:String;OldPattern,NewPattern:Array Of String):String;
  //缓冲区转化为整数
  Function BufToInt(Buf:Buffer; Var Start:Integer):Integer;
  //整数转化为缓冲区
  Procedure IntToBuf(Var Buf:Buffer;Transint:Integer;Var Start:Integer);
  //缓冲区转化为字符串
  Function BufToStr(Buf:Buffer;Var Start:Integer;Len:Byte):String;
  //字符串转化为缓冲区
  Procedure StrToBuf(Var Buf:Buffer;Str:String;Var Start:Integer;Len:Integer);
  //字节转化为整数
  Function Byte4ToInt(Count:Byte4):LongWord;
  //整数转化为字节
  Function IntToByte4(MakeData:Longword):Byte4;
  //加密缓冲区
  Function AddKeyOfBuf(InBuf:buffer;Key:String;Var OutBuf:Buffer;BufLen,OffSet:Integer):Integer;
  //解密缓冲区
  Function DeleteKeyOfBuf(InBuf:Buffer;Key:string;Var OutBuf:Buffer;BufLen,OffSet:integer):Integer;
  //获取指定时间的当月总的天数
  Function GetDaysOfMonth(CurrentDate:TDatetime):Integer;
  //判断一个串是否是小于等于Len个字
  Function IsLessSomeWordFromStr(Str:String;Len:Integer):Boolean;
  //获取一个串的Len个字
  Function GetSomeWordFromStr(Var Str:String;Len:Integer):String;
  //获取一个串的字数
  Function GetWordCountOfStr(Str:String):Integer;
  //获取一段时间内总的天数
  Function GetDays(StartDate,EndDate:TDateTime):Integer;
  //判断是否是数字数据
  Function IsNumberData(Key:Char):Integer;
  //判断是否是字符数据
  Function IsCharData(Key:Char):Integer;
  //判断是否是字符或数字数据
  Function IsNumCharData(Key:Char):Integer;
  //分解一个字符串Str中包含子字符串Chr的两个子字符串(PreStr和NextStr)
  Procedure GetPreStrFromStrOfChr(Chr,Str:String);
  //截取浮点型的两位小位数
  Function FormatFlt2Str(Inflt:Real):String;

Implementation
  Uses U_AddKeyToBuf,U_DeleteKey,U_OtherPublicPack,U_DBPublicPack;

//计算一个字符串的加法算法
Function Add(Str:String):String;
Begin
  Try
    Result:=FloatToStr(StrToFloat(Copy(Str,1,Pos(Str,'+')))+StrToFloat(Copy(Str,Pos(Str,'+')+1,Length(Str)-Pos(Str,'+'))));
  Except
    Result:='';
  End;
End;
//计算一个字符串的减法算法
Function Sub(Str:String):String;
Begin
  Try
    Result:=FloatToStr(StrToFloat(Copy(Str,1,Pos(Str,'-'))) - StrToFloat(Copy(Str,Pos(Str,'-')+1,Length(Str)-Pos(Str,'-'))));
  Except
    Result:='';
  End;
End;
//计算一个字符串的乘法算法
Function Mul(Str:String):String;
Begin
  Try
    Result:=FloatToStr(StrToFloat(Copy(Str,1,Pos(Str,'*'))) * StrToFloat(Copy(Str,Pos(Str,'*')+1,Length(Str)-Pos(Str,'*'))));
  Except
    Result:='';
  End;
End;
//计算一个字符串的除法算法
Function Divi(Str:String):String;
Begin
  Try
    Result:=FloatToStr(StrToFloat(Copy(Str,1,Pos(Str,'/'))) / StrToFloat(Copy(Str,Pos(Str,'/')+1,Length(Str)-Pos(Str,'/'))));
  Except
    Result:='';
  End;
End;
//一个多项式的计算算法
Function ComputeStr(Str:String):String;
Var
  StartStr,EndStr:String;
Begin
  While (Pos('*',Str)<>0) Or (Pos('/',Str)<>0) Do
  Begin
    If ((Pos('*',Str)<Pos('/',Str)) And (Pos('*',Str)<>0)) Or (Pos('/',Str)=0) Then
    Begin
      StartStr:=Copy(Str,1,Pos('*',Str)-1);
      EndStr:=Copy(Str,Pos('*',Str)+1,Length(Str)-Pos('*',Str));
      If StartStr=GetFirst(StartStr) Then
        If GetLast(EndStr)=EndStr Then
          Str:=FloatToStr(StrToFloat(GetFirst(StartStr)) * StrToFloat(GetLast(EndStr)))
        Else
          Str:=FloatToStr(StrToFloat(GetFirst(StartStr)) * StrToFloat(GetLast(EndStr)))+Copy(EndStr,Length(GetLast(EndStr))+1,Length(EndStr)-Length(GetLast(EndStr)))
      Else
        If GetLast(EndStr)<>EndStr Then
          Str:=Copy(StartStr,1,Length(StartStr)-Length(GetFirst(StartStr)))+FloatToStr(StrToFloat(GetFirst(StartStr)) * StrToFloat(GetLast(EndStr)))+Copy(EndStr,Length(GetLast(EndStr))+1,Length(EndStr)-Length(GetLast(EndStr)))
        Else
          Str:=Copy(StartStr,1,Length(StartStr)-Length(GetFirst(StartStr)))+FloatToStr(StrToFloat(GetFirst(StartStr)) * StrToFloat(GetLast(EndStr)));
    End
    Else
    Begin
      StartStr:=Copy(Str,1,Pos('/',Str)-1);
      EndStr:=Copy(Str,Pos('/',Str)+1,Length(Str)-Pos('/',Str));
      If StartStr=GetFirst(StartStr) Then
        If GetLast(EndStr)=EndStr Then
          Str:=FloatToStr(StrToFloat(GetFirst(StartStr)) / StrToFloat(GetLast(EndStr)))
        Else
          Str:=FloatToStr(StrToFloat(GetFirst(StartStr)) / StrToFloat(GetLast(EndStr)))+Copy(EndStr,Length(GetLast(EndStr))+1,Length(EndStr)-Length(GetLast(EndStr)))
      Else
        If GetLast(EndStr)<>EndStr Then
          Str:=Copy(StartStr,1,Length(StartStr)-Length(GetFirst(StartStr)))+FloatToStr(StrToFloat(GetFirst(StartStr)) / StrToFloat(GetLast(EndStr)))+Copy(EndStr,Length(GetLast(EndStr))+1,Length(EndStr)-Length(GetLast(EndStr)))
        Else
          Str:=Copy(StartStr,1,Length(StartStr)-Length(GetFirst(StartStr)))+FloatToStr(StrToFloat(GetFirst(StartStr)) / StrToFloat(GetLast(EndStr)));
    End;
  End;
  While (Pos('+',Str)<>0) Or ((Pos('-',Str)<>0)) Do
  Begin
    If (((Pos('+',Str)<Pos('-',Str)) Or (Str[1]='-')) And (Pos('+',Str)<>0)) Or (Pos('-',Str)=0) Then
    Begin
      StartStr:=Copy(Str,1,Pos('+',Str)-1);
      EndStr:=Copy(Str,Pos('+',Str)+1,Length(Str)-Pos('+',Str));
      If StartStr=GetFirst(StartStr) Then
        If GetLast(EndStr)=EndStr Then
          Str:=FloatToStr(StrToFloat(GetFirst(StartStr)) + StrToFloat(GetLast(EndStr)))
        Else
          Str:=FloatToStr(StrToFloat(GetFirst(StartStr)) + StrToFloat(GetLast(EndStr)))+Copy(EndStr,Length(GetLast(EndStr))+1,Length(EndStr)-Length(GetLast(EndStr)))
      Else
        If GetLast(EndStr)<>EndStr Then
          Str:=Copy(StartStr,1,Length(StartStr)-Length(GetFirst(StartStr)))+FloatToStr(StrToFloat(GetFirst(StartStr)) + StrToFloat(GetLast(EndStr)))+Copy(EndStr,Length(GetLast(EndStr))+1,Length(EndStr)-Length(GetLast(EndStr)))
        Else
          Str:=Copy(StartStr,1,Length(StartStr)-Length(GetFirst(StartStr)))+FloatToStr(StrToFloat(GetFirst(StartStr)) + StrToFloat(GetLast(EndStr)));
    End
    Else
    Begin
      If Str[1]='-' Then
      Begin
        If Pos('-',Copy(Str,2,Length(Str)-1))=0 Then
        Begin
          Result:=Str;
          Exit;
        End;
        StartStr:=Copy(Str,1,Pos('-',Copy(Str,2,Length(Str)-1)));
        EndStr:=Copy(Str,Pos('-',Copy(Str,2,Length(Str)-1))+2,Length(Str)-Pos('-',Copy(Str,2,Length(Str)-1))-1);
      End
      Else
      Begin
        StartStr:=Copy(Str,1,Pos('-',Str)-1);
        EndStr:=Copy(Str,Pos('-',Str)+1,Length(Str)-Pos('-',Str));
      End;
      If StartStr=GetFirst(StartStr) Then
        If GetLast(EndStr)=EndStr Then
          Str:=FloatToStr(StrToFloat(GetFirst(StartStr)) - StrToFloat(GetLast(EndStr)))
        Else
          Str:=FloatToStr(StrToFloat(GetFirst(StartStr)) - StrToFloat(GetLast(EndStr)))+Copy(EndStr,Length(GetLast(EndStr))+1,Length(EndStr)-Length(GetLast(EndStr)))
      Else
        If GetLast(EndStr)<>EndStr Then
          Str:=Copy(StartStr,1,Length(StartStr)-Length(GetFirst(StartStr)))+FloatToStr(StrToFloat(GetFirst(StartStr)) - StrToFloat(GetLast(EndStr)))+Copy(EndStr,Length(GetLast(EndStr))+1,Length(EndStr)-Length(GetLast(EndStr)))
        Else
          Str:=Copy(StartStr,1,Length(StartStr)-Length(GetFirst(StartStr)))+FloatToStr(StrToFloat(GetFirst(StartStr)) - StrToFloat(GetLast(EndStr)));
    End;
  End;
  Result:=Str;
End;
//获取字符串的第一个数据
Function GetFirst(Str:String):String;
Var
  Count:Integer;
Begin
  Count:=Length(Str);
  While (Not(Str[Count] In ['*','/','-','+']) And (Count<>1)) Do
    Dec(Count);
  If Count=1 Then
  Begin
    Result:=Str;
    Exit;
  End;
  If (Str[Count-1] In ['*','/','-','+']) Then
    Result:=Copy(Str,Count,Length(Str)-Count+1)
  Else
    Result:=Copy(Str,Count+1,Length(Str)-Count);
End;
//获取字符串的最后一个数据
Function GetLast(Str:String):String;
Var
  Count:Integer;
Begin
  If Str='' Then
    Exit;
  Count:=1;
  If Str[1]='-' Then
    Inc(Count);
  While Not(Str[Count] In ['/','*','+','-']) Do
  Begin
    If Count=Length(Str) Then
      Break;
    Inc(Count);
  End;
  If Count=Length(Str) Then
    Result:=Str
  Else
    Result:=Copy(Str,1,Count-1);
End;
//获取一个字符串的值
Function GetValue(Str:String):String;
Var
  StartStr,EndStr:String;
  StartPos,EndPos:Integer;
Begin
  StartStr:=Str;
  StartPos:=0;
  If Pos('(',StartStr)=0 Then
  Begin
    Result:=ComputeStr(StartStr);
    Exit;
  End;
  While Pos('(',StartStr)<>0 Do
  Begin
    StartPos:=StartPos+Pos('(',StartStr);
    EndPos:=Pos(')',Str);
    If EndPos<StartPos Then
    Begin
      StartPos:=StartPos-Pos('(',StartStr);
      If EndPos=Length(Str) Then
        Result:=Copy(Str,1,StartPos-1)+ComputeStr(Copy(Str,StartPos+1,EndPos-StartPos-1))
      Else
        Result:=Copy(Str,1,StartPos-1)+ComputeStr(Copy(Str,StartPos+1,EndPos-StartPos-1))+Copy(Str,EndPos+1,Length(Str)-EndPos);
      Exit;
    End
    Else
    Begin
      StartStr:=Copy(Str,StartPos+1,Length(Str)-StartPos);
      If StartStr=Str Then
      Begin
        Result:=ComputeStr(StartStr);
        Exit;
      End;
    End;
  End;
  EndPos:=Pos(')',Str);
  If EndPos=Length(Str) Then
    Result:=Copy(Str,1,StartPos-1)+ComputeStr(Copy(Str,StartPos+1,EndPos-StartPos-1))
  Else
    Result:=Copy(Str,1,StartPos-1)+ComputeStr(Copy(Str,StartPos+1,EndPos-StartPos-1))+Copy(Str,EndPos+1,Length(Str)-EndPos);
End;
//获取当天的星期
Function GetWeekOfDay(CurrentDate:TDate):String;
Begin
  Case DayOfWeek(CurrentDate-1) Of
    1:Result:='星期一';
    2:Result:='星期二';
    3:Result:='星期三';
    4:Result:='星期四';
    5:Result:='星期五';
    6:Result:='星期六';
    7:Result:='星期日';
  End;
End;
//设置字符对齐方式(以PlaceChar补位)
Function SetStringWidth(Str,PlaceChar:String;Width:Integer;Option{为1是左对齐为2是右对齐}:Integer):String;
Var
  i:Integer;
  TempBlank:String;
Begin
  TempBlank:='';
  If Length(Str)>=Width Then
    Result:=Trim(Str)
  Else
  Begin
    For i:=1 To Width-Length(Trim(Str)) Do
      TempBlank:=TempBlank+PlaceChar;
    //option为1-左对齐2-右对齐
    If Option=1 Then
      Result:=Trim(Str)+TempBlank;
    If Option=2 Then
      Result:=TempBlank+Trim(Str);
  End;
End;
//字符多种替换过程
Function MulReplace(Info:String;OldPattern,NewPattern:Array Of String):String;
Var
  i,ilow,ihigh:Integer;
  InfoTemp:String;
Begin    
  InfoTemp:=Info;
  ilow:=Low(OldPattern);
  iHigh:=High(OldPattern);
  For i:=ilow To ihigh Do
    InfoTemp:=StringReplace(InfoTemp,OldPattern[i],NewPattern[i],[rfReplaceAll]);
  Result:=InfoTemp;
End;
//缓冲区转化为整数
Function BufToInt(Buf:Buffer; Var Start:Integer):Integer;
Var
  ByteInt:Byte4;
Begin
  //内存缓冲复制
  CopyMemory(@ByteInt,Buf+Start,4);
  Result:=Byte4ToInt(ByteInt);
  Start:=Start+4;
End;

//整数转化为缓冲区
Procedure IntToBuf(Var Buf:Buffer;Transint:Integer;Var Start:Integer);
Var
  ByteInt:Byte4;
Begin
  ByteInt:=IntToByte4(TransInt);
  CopyMemory(Buf+Start,@ByteInt,4);
  Start:=Start+4;
End;

⌨️ 快捷键说明

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