u_stringpublicpack.pas

来自「SQL的应用」· PAS 代码 · 共 535 行 · 第 1/2 页

PAS
535
字号
    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 GetDaysOfMonth(CurrentDate:TDatetime):Integer;
Var
  Current:TDateTime;
  Str:String;
Begin
  Str:=FormatDateTime('YYYY-MM',IncMonth(CurrentDate))+'-01';
  Current:=StrToDateTime(Str);
  Result:=DayOf(Current-1);
End;
//判断一个串是否是小于等于Len个字
Function IsLessSomeWordFromStr(Str:String;Len:Integer):Boolean;
Var
  WordCount,Index,StrLen:Integer;
Begin
  Result:=True;
  //获取字符串的字节数目
  StrLen:=Length(Str);
  //处始设置字数为0
  WordCount:=0;
  Index:=1;
  //遍历整个字符串
  While Index<=StrLen Do
  Begin
    //判断字数是否大于Len个字
    If WordCount>Len Then
    Begin
      Result:=False;
      //退出群环
      Break;
    End;
    //判断该字符是否是汉字还是普通字符
    If Str[Index]>#127 Then
      Index:=Index+2
    Else
      Index:=Index+1;
    //字数递增1
    Inc(WordCount);
  End;
  //判断字数是否小于等于Len个字同时索引小于字符串长度
  If (WordCount<=Len) And (Index>=StrLen) Then
    //返回原串
    Result:=True
  Else
    Result:=False;
End;
//获取一个串的Len个字
Function GetSomeWordFromStr(Var Str:String;Len:Integer):String;
Var
  WordCount,Index,StrLen:Integer;
Begin
  //获取字符串的字节数目
  StrLen:=Length(Str);
  //处始设置字数为0
  WordCount:=0;
  Index:=1;
  //遍历整个字符串
  While Index<=StrLen Do
  Begin
    //判断字数是否大于Len个字
    If WordCount>=Len Then
    Begin
      Result:=Copy(Str,1,Index-1);
      //获取字符串前Len个字
      Str:=Copy(Str,Index,StrLen-Index+1);
      //退出函数
      Exit;
    End;
    //判断该字符是否是汉字还是普通字符
    If Str[Index]>#127 Then
      Index:=Index+2
    Else
      Index:=Index+1;
    //字数递增1  
    Inc(WordCount);
  End;
  //判断字数是否小于等于Len个字同时索引小于字符串长度
  If (WordCount<=Len) And (Index>=StrLen) Then
  Begin
    //返回原串
    Result:=Str;
    Str:='';
  End;
End;
//获取一个串的字数
Function GetWordCountOfStr(Str:String):Integer;
Var
  WordCount,Index,StrLen:Integer;
Begin
  StrLen:=Length(Str);
  WordCount:=0;
  Index:=1;
  While Index<=StrLen Do
  Begin
    If Str[Index]>#127 Then
      Index:=Index+2
    Else
      Index:=Index+1;
    Inc(WordCount);
  End;
  Result:=WordCount;
End;
//获取一段时间内总的天数
Function GetDays(StartDate,EndDate:TDateTime):Integer;
Var
  Current:TDateTime;
  Str:String;
  Count,StartMonth,EndMonth:Integer;
Begin
  StartMonth:=MonthOf(StartDate);
  EndMonth:=MonthOf(EndDate);
  If StartMonth>EndMonth Then
  Begin
    Result:=-1;
    Exit;
  End;           
  If StartMonth=EndMonth Then
  Begin
    Result:=DayOf(EndDate)-DayOf(StartDate);
    Exit;
  End;
  Current:=StartDate;
  Result:=GetDaysOfMonth(StartDate)-DayOf(StartDate);
  For Count:=StartMonth+1 To EndMonth Do
  Begin
    If Count=EndMonth Then
    Begin
      Result:=Result+DayOf(EndDate);
      Continue;
    End;
    Current:=IncMonth(Current);
    Result:=Result+GetDaysOfMonth(Current);
  End;
End;
//判断是否是数字数据
Function IsNumberData(Key:Char):Integer;
Begin
  If Not (Key In ['0'..'9']) Then
  Begin
    Key:=#0;
    Result:=1;
  End
  Else
    Result:=0;
End;
//判断是否是字符数据
Function IsCharData(Key:Char):Integer;
Begin
  If Not ((Key In ['a'..'z']) Or (Key In ['A'..'Z'])) Then
  Begin
    Key:=#0;
    Result:=1;
  End
  Else
    Result:=0;
End;
//判断是否是字符或数字数据
Function IsNumCharData(Key:Char):Integer;
Begin
  If Not ((Key In ['0'..'9']) Or (Key In ['a'..'z']) Or (Key In ['A'..'Z'])) Then
  Begin
    Key:=#0;
    Result:=1;
  End
  Else
    Result:=0;
End;
//分解一个字符串Str中包含子字符串Chr的两个子字符串(PreStr和NextStr)
Procedure GetPreStrFromStrOfChr(Chr,Str:String);
Var
  PreStr,NextStr:String;
  ChrLen,StrLen,Position:Integer;
Begin
  ChrLen:=Length(Chr);//替换串长度
  StrLen:=Length(Str);//原串长度
  Position:=Pos(Chr,Str);//获取原串中包含替换串的位置
  If Position=0 Then
  Begin
    PreStr:=Str;
    NextStr:='';
    If PreStr='' Then
      Exit;
    {
    **************************
    ***对PreStr字符串的操作***
    **************************
    }
    Exit;
  End
  Else
  Begin
    If Position=1 Then
    Begin
      PreStr:='';
      NextStr:=Copy(Str,Position+ChrLen,StrLen-ChrLen-Position+1);
    End
    Else
    Begin
      PreStr:=Copy(Str,1,Position-1);
      NextStr:=Copy(Str,Position+ChrLen,StrLen-ChrLen-Position+1);
    End;
  End;
  {
  **************************
  ***对PreStr字符串的操作***
  **************************
  }
  GetPreStrFromStrOfChr(Chr,NextStr);
End;
//截取浮点型的两位小位数
Function FormatFlt2Str(Inflt:Real):String;
Begin
  Try
    If inflt<0 Then
    Begin
      Result:=FormatFloat('0.00',Inflt);
    End
    Else
    Begin
      Result:='+'+FormatFloat('0.00',Inflt);
    End;
  Except
  End;
End;

End.

⌨️ 快捷键说明

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