Delphi 逐个分解后字符串加载到StringGrid1


本文整理自网络,侵删。

 

procedure TForm1.sEdit1Change(Sender: TObject);
procedure TForm1.sEdit1Change(Sender: TObject);
var
  i: integer;
  str: string;
  c: char;
  arr: array[0..200, 0..200] of string;
  A, j: integer;
begin
  str := sedit1.text;
  for i := 0 to length(str) do
  begin
    c := str[i];
   //ShowMessage(c);
    arr[0][0] := '分解后字符串';
    arr[1][0] := '索引';
    arr[2][0] := '切片时索引';
    StringGrid1.RowCount := 3;      //这个是行数
    StringGrid1.ColCount := i + 2;   //这个是列数  (列数+1才对啊)
    StringGrid1.ColWidths[0] := 0;
    StringGrid1.ColWidths[1] := 130;
 
    arr[0][i] := c;             //这个是分解后的单个字符中的第1行
    arr[1][i] := IntToStr(i - 1);  //这个是分解后对应的索引,也就是第2行
 
    arr[2][i] := '-' + IntToStr(length(str) - i + 1);


  end;
//ShowMessage(IntToStr(i - 1));
  for A := Low(arr) to High(arr) do                  //这个是调整表格,隐藏第一列的!
    for j := Low(arr[A]) + 1 to High(arr[A]) + 1 do
    begin
      StringGrid1.Cells[j, A] := arr[A][j - 1]
    end;
end;

来源:https://www.52pojie.cn/thread-1296701-1-1.html

相关阅读 >>

Delphi timage保存图片到stream及从stream中取图片

Delphi判断字符串是否是数字、字母、大小写字母

Delphi 提升进程令牌

Delphi 读取网上的文本文件

Delphi与进程、窗口句柄、文件属性、程序运行状态

Delphi中带缓存的数据更新技术

Delphi 网上获取北京时间firedac 下的 sqlite [3] - 获取数据库的基本信息

Delphi 长文件路径转换短文件路径

Delphi case 语句中使用字符串

Delphi使用迅雷的开放下载引擎下载

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...