2 Star 0 Fork 0

MJ PC Lab/CodingAssistant

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Unit_UtilitySequence.pas 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
小小猫猫 提交于 2014-04-13 05:07 +08:00 . make project GIT controlled.
unit Unit_UtilitySequence;
interface
uses SysUtils,Classes,StrUtils;
type TCodeUtilitySequence=class
private const
newLine:string=#13#10;
doubleNewLine:string=#13#10#13#10;
private
FLines:TStrings;
public
constructor Create(theLines:TStrings);
property Lines:TStrings read FLines write FLines;
procedure SequenceToEndValue(const template,placeHolder,formatString:string; const startValue,stepLength,endValue:Integer);
procedure SequenceByRepeatCount(const template,placeHolder,formatString:string;const startValue,stepLength,repeatCount:Integer);
end;
implementation
{ TCodeUtilitySequence }
constructor TCodeUtilitySequence.Create(theLines: TStrings);
begin
//Bind a TStrings to the class.
FLines:=theLines;
end;
procedure TCodeUtilitySequence.SequenceToEndValue(const template,placeHolder,formatString:string; const startValue,stepLength,endValue:Integer);
var i:Integer;
var current,currentEntry:string;
var buffer:TStrings;
begin
if stepLength<>0 then begin
buffer:=TStringList.Create;
i:=startValue;
while ((stepLength>0) and (i<=endValue)) or ((stepLength<0) and (i>=endValue)) do begin
//do something
if Length(formatString)=0 then begin
current:=IntToStr(i);
end else begin
current:=Format(formatString,[i]);
end;
currentEntry:=StringReplace(template,placeHolder,current,[rfReplaceAll]);
buffer.Append(currentEntry);
i:=i+stepLength;
end;
FLines.Add(buffer.Text);
if FLines.Strings[FLines.Count-1]='' then FLines.Delete(FLines.Count-1);
buffer.Free;
end;
end;
procedure TCodeUtilitySequence.SequenceByRepeatCount(const template,placeHolder,formatString:string;const startValue,stepLength,repeatCount:Integer);
var i,repeated:Integer;
var current,currentEntry:string;
var buffer:TStrings;
begin
buffer:=TStringList.Create;
i:=startValue;
for repeated := 1 to repeatCount do begin
//do something
if Length(formatString)=0 then begin
current:=IntToStr(i);
end else begin
current:=Format(formatString,[i]);
end;
currentEntry:=StringReplace(template,placeHolder,current,[rfReplaceAll]);
buffer.Append(currentEntry);
i:=i+stepLength;
end;
FLines.Add(buffer.Text);
if FLines.Strings[FLines.Count-1]='' then FLines.Delete(FLines.Count-1);
buffer.Free;
end;
end.
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Delphi
1
https://gitee.com/mjpclab/CodingAssistant.git
git@gitee.com:mjpclab/CodingAssistant.git
mjpclab
CodingAssistant
CodingAssistant
master

搜索帮助