最牛论坛

查看: 1456|回复: 0

用Delphi生成Python切片对应的表格

[复制链接]

1万

主题

2419

回帖

537万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5379876
发表于 2020-11-4 12:05 | 显示全部楼层 |阅读模式
110429wf0hhrhovvythf6y_副本.png
一日楼主看到如此教程,心中大悦,何不用咱家的Delphi生成一个表格以观之,岂不大大的舒服呢?
所以赶紧动手开始吧~~
因为需要原始字符串,和分解后的字符串
索引
-1反向索引
所以最少需要3行-4行 (输入栏你得一行吧?) 也就按3行算好了。

112556o57kloft6hpfovoe_副本.png
生成后的效果~~
  1. procedure TForm1.sEdit1Change(Sender: TObject);
  2. [size=14px]procedure TForm1.sEdit1Change(Sender: TObject);[/size]
  3. [size=14px]var[/size]
  4. [size=14px]  i: integer;[/size]
  5. [size=14px]  str: string;[/size]
  6. [size=14px]  c: char;[/size]
  7. [size=14px]  arr: array[0..200, 0..200] of string;[/size]
  8. [size=14px]  A, j: integer;[/size]
  9. [size=14px]begin[/size]
  10. [size=14px]  str := sedit1.text;[/size]
  11. [size=14px]  for i := 0 to length(str) do[/size]
  12. [size=14px]  begin[/size]
  13. [size=14px]    c := str[i];[/size]
  14. [size=14px]   //ShowMessage(c);[/size]
  15. [size=14px]    arr[0][0] := '分解后字符串';[/size]
  16. [size=14px]    arr[1][0] := '索引';[/size]
  17. [size=14px]    arr[2][0] := '切片时索引';[/size]
  18. [size=14px]    StringGrid1.RowCount := 3;      //这个是行数[/size]
  19. [size=14px]    StringGrid1.ColCount := i + 2;   //这个是列数  (列数+1才对啊)[/size]
  20. [size=14px]    StringGrid1.ColWidths[0] := 0;[/size]
  21. [size=14px]    StringGrid1.ColWidths[1] := 130;[/size]

  22. [size=14px]    arr[0][i] := c;             //这个是分解后的单个字符中的第1行[/size]
  23. [size=14px]    arr[1][i] := IntToStr(i - 1);  //这个是分解后对应的索引,也就是第2行[/size]

  24. [size=14px]    arr[2][i] := '-' + IntToStr(length(str) - i + 1);[/size]
  25. [size=14px]
  26. [/size]
  27. [size=14px]  end;[/size]
  28. [size=14px]//ShowMessage(IntToStr(i - 1));[/size]
  29. [size=14px]  for A := Low(arr) to High(arr) do                  //这个是调整表格,隐藏第一列的![/size]
  30. [size=14px]    for j := Low(arr[A]) + 1 to High(arr[A]) + 1 do[/size]
  31. [size=14px]    begin[/size]
  32. [size=14px]      StringGrid1.Cells[j, A] := arr[A][j - 1][/size]
  33. [size=14px]    end;[/size]
  34. [size=14px]end;[/size]
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Powered by Discuz! X3.4

© 2019-2024 Comsenz Inc.

返回顶部