|
|
一日楼主看到如此教程,心中大悦,何不用咱家的Delphi生成一个表格以观之,岂不大大的舒服呢?
所以赶紧动手开始吧~~
因为需要原始字符串,和分解后的字符串
索引
-1反向索引
所以最少需要3行-4行 (输入栏你得一行吧?) 也就按3行算好了。
生成后的效果~~
- procedure TForm1.sEdit1Change(Sender: TObject);
- [size=14px]procedure TForm1.sEdit1Change(Sender: TObject);[/size]
- [size=14px]var[/size]
- [size=14px] i: integer;[/size]
- [size=14px] str: string;[/size]
- [size=14px] c: char;[/size]
- [size=14px] arr: array[0..200, 0..200] of string;[/size]
- [size=14px] A, j: integer;[/size]
- [size=14px]begin[/size]
- [size=14px] str := sedit1.text;[/size]
- [size=14px] for i := 0 to length(str) do[/size]
- [size=14px] begin[/size]
- [size=14px] c := str[i];[/size]
- [size=14px] //ShowMessage(c);[/size]
- [size=14px] arr[0][0] := '分解后字符串';[/size]
- [size=14px] arr[1][0] := '索引';[/size]
- [size=14px] arr[2][0] := '切片时索引';[/size]
- [size=14px] StringGrid1.RowCount := 3; //这个是行数[/size]
- [size=14px] StringGrid1.ColCount := i + 2; //这个是列数 (列数+1才对啊)[/size]
- [size=14px] StringGrid1.ColWidths[0] := 0;[/size]
- [size=14px] StringGrid1.ColWidths[1] := 130;[/size]
-
- [size=14px] arr[0][i] := c; //这个是分解后的单个字符中的第1行[/size]
- [size=14px] arr[1][i] := IntToStr(i - 1); //这个是分解后对应的索引,也就是第2行[/size]
-
- [size=14px] arr[2][i] := '-' + IntToStr(length(str) - i + 1);[/size]
- [size=14px]
- [/size]
- [size=14px] end;[/size]
- [size=14px]//ShowMessage(IntToStr(i - 1));[/size]
- [size=14px] for A := Low(arr) to High(arr) do //这个是调整表格,隐藏第一列的![/size]
- [size=14px] for j := Low(arr[A]) + 1 to High(arr[A]) + 1 do[/size]
- [size=14px] begin[/size]
- [size=14px] StringGrid1.Cells[j, A] := arr[A][j - 1][/size]
- [size=14px] end;[/size]
- [size=14px]end;[/size]
复制代码
|
|