Delphi Pos的德尔菲定位

Delphi Pos的德尔菲定位,delphi,Delphi,所以我有以下代码可以工作: function TForm2.SearchForm(Count: Integer): String; var i,a,a1: integer; s,s0,s1,s2: string; begin s := Memo1.Text; for i := 0 to Count-1 do begin a:=Pos('"last_ten_starts":"',s); s0:=Copy(s, 1, a); Delete(s, 1, a+

所以我有以下代码可以工作:

function TForm2.SearchForm(Count: Integer): String;
var
  i,a,a1: integer;
  s,s0,s1,s2: string;
begin
  s := Memo1.Text;
  for i := 0 to Count-1 do
  begin
    a:=Pos('"last_ten_starts":"',s);
    s0:=Copy(s, 1, a);
    Delete(s, 1, a+18);
    a:=Pos('"', s);
    s1:=Copy(s, 1, a-1);//copy last 10 runs
    s2:=Copy(s1, Length(s1)-3, Length(s1));//get last 4 runs
    Memo1.Lines.Append('Form (x10): '+s1+ ' Form (x4): '+s2);
    if (s2 = '1111') or (s2 = '111x') or (s2 = '11x1') or (s2 = '1x11') or (s2 = 'x111') then
    begin
      Log(s0);
      ShowMessage('Pos: '+IntToStr(a));
    end;
  end;
end;

function TForm2.GetRaceNumber(Count: Integer): string;
var
  s, s1: string;
  i, a, a1: integer;
begin
  s := Memo1.Text;
  for i := 0 to Count-1 do
  begin
    a:=Pos('"RaceForm":{"@number":"',s);
    Copy(s, 1, a);
    Delete(s, 1, a+22);
    a1:=Pos('"', s);
    s1:=Copy(s, 1, a1-1);//copy race number
  end;
end;
一切都很好,代码工作正常,有点凌乱,但稍后可能会进行清理。我对如何着手做某事感到有点困惑

这让我感到困惑,我甚至在努力解释我需要在这里尝试和做什么

所以“马形”:{“@number”:“有8次出现,在这些出现之间大约有90次“最后十次开始”)。我需要做的是检查马形的所有8个位置,以确定最后十次开始是否是比赛1到8

这有意义吗

编辑:这里是我的文本示例(顺便说一句,我正在阅读html备忘并搜索文本)

所以在位置1和位置2之间,我想阅读所有的“最后十次出发”并将它们作为比赛1。在位置2和3之间的“最后十次出发”将是比赛2

目前,最后十场比赛是这样开始的:

Form (x10): 6x49559545 Form (x4): 9545
Form (x10): 80x1071684 Form (x4): 1684
Form (x10): 9185215877 Form (x4): 5877
Form (x10): 5530017849 Form (x4): 7849
Form (x10): 4x83373x56 Form (x4): 3x56
Form (x10): 5970636148 Form (x4): 6148
Form (x10): 8x25785511 Form (x4): 5511
Form (x10): 668670x763 Form (x4): x763
Form (x10): x43530x956 Form (x4): x956
Form (x10): 83x2x11113 Form (x4): 1113
Form (x10): 15x3214533 Form (x4): 4533
Form (x10): 2149x8x830 Form (x4): x830
Form (x10): 6127x46325 Form (x4): 6325
但是要让代码在位置块之间读取它们,然后像这样放置它们:

Race 1: Form (x10): 6x49559545 Form (x4): 9545
Race 1: Form (x10): 80x1071684 Form (x4): 1684
Race 1: Form (x10): 9185215877 Form (x4): 5877
Race 2: Form (x10): 5530017849 Form (x4): 7849
Race 2: Form (x10): 4x83373x56 Form (x4): 3x56
Race 3: Form (x10): 5970636148 Form (x4): 6148
Race 4: Form (x10): 8x25785511 Form (x4): 5511
Race 4: Form (x10): 668670x763 Form (x4): x763
Race 5: Form (x10): x43530x956 Form (x4): x956
Race 6: Form (x10): 83x2x11113 Form (x4): 1113
Race 7: Form (x10): 15x3214533 Form (x4): 4533
Race 8: Form (x10): 2149x8x830 Form (x4): x830
Race 8: Form (x10): 6127x46325 Form (x4): 6325

您可以同时扫描两种模式的文本。我建议使用
PosEx
从最后一个位置继续搜索,而不删除字符串。伪代码:

RaceNum := 0;
LastPos := 1;
RacePos := PosEx('"RaceForm":{"@number":"', s, LastPos);
TenPos := PosEx('"last_ten_starts":"', s, LastPos);

while (RacePos > 0)  or (TenPos > 0) do begin

   if (RacePos > 0) then
      if (TenPos = 0) or (RacePos < TenPos) then begin
          Extract RaceNumber from race record
          //Update LastPos to the end of race record:
          LastPos := LastPos + Length('"RaceForm":{"@number":"');   
       end;

   if (TenPos > 0) then
      if (RacePos = 0) or (RacePos > TenPos) then begin
          Extract last_ten record
          Assign it to the current RaceNumber
          //Update LastPos to the end of last_ten record
          LastPos := LastPos + Length('"last_ten_starts":"');   
       end;

   RacePos := PosEx('"RaceForm":{"@number":"', s, LastPos);
   TenPos := PosEx('"last_ten_starts":"', s, LastPos);
end;
RaceNum:=0;
LastPos:=1;
RacePos:=PosEx(“'RaceForm:{@number:”,s,LastPos);
TenPos:=PosEx(“'last\u ten\u start:”,s,LastPos);
当(RacePos>0)或(TenPos>0)确实开始时
如果(RacePos>0),则
如果(TenPos=0)或(RacePos0),则
如果(RacePos=0)或(RacePos>TenPos),则开始
提取最后十条记录
将其分配给当前比赛号码
//将LastPos更新到最近十条记录的末尾
LastPos:=LastPos+长度(“‘最后十次’开始):”);
结束;
RacePos:=PosEx(“'RaceForm:{@number:”,s,LastPos);
TenPos:=PosEx(“'last\u ten\u start:”,s,LastPos);
结束;

您可以同时扫描两种模式的文本。我建议使用
PosEx
从最后一个位置继续搜索,而不删除字符串。伪代码:

RaceNum := 0;
LastPos := 1;
RacePos := PosEx('"RaceForm":{"@number":"', s, LastPos);
TenPos := PosEx('"last_ten_starts":"', s, LastPos);

while (RacePos > 0)  or (TenPos > 0) do begin

   if (RacePos > 0) then
      if (TenPos = 0) or (RacePos < TenPos) then begin
          Extract RaceNumber from race record
          //Update LastPos to the end of race record:
          LastPos := LastPos + Length('"RaceForm":{"@number":"');   
       end;

   if (TenPos > 0) then
      if (RacePos = 0) or (RacePos > TenPos) then begin
          Extract last_ten record
          Assign it to the current RaceNumber
          //Update LastPos to the end of last_ten record
          LastPos := LastPos + Length('"last_ten_starts":"');   
       end;

   RacePos := PosEx('"RaceForm":{"@number":"', s, LastPos);
   TenPos := PosEx('"last_ten_starts":"', s, LastPos);
end;
RaceNum:=0;
LastPos:=1;
RacePos:=PosEx(“'RaceForm:{@number:”,s,LastPos);
TenPos:=PosEx(“'last\u ten\u start:”,s,LastPos);
当(RacePos>0)或(TenPos>0)确实开始时
如果(RacePos>0),则
如果(TenPos=0)或(RacePos0),则
如果(RacePos=0)或(RacePos>TenPos),则开始
提取最后十条记录
将其分配给当前比赛号码
//将LastPos更新到最近十条记录的末尾
LastPos:=LastPos+长度(“‘最后十次’开始):”);
结束;
RacePos:=PosEx(“'RaceForm:{@number:”,s,LastPos);
TenPos:=PosEx(“'last\u ten\u start:”,s,LastPos);
结束;

是的,你的解释不好。请把问题说得更清楚,并展示文本示例。是的,很抱歉解释有点困难,希望我能解释得更好一些。是的,你的解释不好。请把问题说得更清楚,并展示文本示例。是的,很抱歉解释有点困难,希望我能解释得更清楚一点t是的,谢谢,这是我的问题!获取lastpos我也不知道不删除字符串片段也可以做到,因为我这样做会弄乱字符的位置。谢谢,这非常有用!要获取新的
lastpos
值,请按模式的长度递增,如
NextPos:=PosEx('“,s,座圈位置+长度(座圈))
Race是字符串。在这种情况下,逻辑可能会变得太复杂。请参阅if conditions and Lastpos addition中的我的更新。是的,谢谢,这是我的问题!获取lastposi也不知道不删除字符串片段就可以做到这一点,因为我这样做会弄乱字符的位置。谢谢,这非常有帮助设置new
lastpos
value,将其按模式查找的长度递增,如
NextPos:=PosEx(“”,s,RacePos+length(Race));
Race为字符串。在这种情况下,逻辑可能变得太复杂。请参阅if条件和lastpos添加中的我的更新