关于listbox的add求教 有一个长度为10的字符串,例如‘113300##03’;要将其中的#转化为‘0’‘1’‘3’,再将字符串输出,初学Delphi.求高手指点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 将字符串113300##03里的#替换为'0','1','3'?????还是'013'和在一起的?可以使用stringreplace函数将#替换成相应字符串 有一个长度为10的字符串,例如‘113300##03’;要将其中的#转化为‘0’‘1’‘3’,再将字符串输出,初学Delphi.求高手指点就是要转化为‘1133000003’‘1133000103’‘1133000303’ ‘1133001#03’‘1133001003’‘1133001303’ ‘1133003003’‘1133003103’‘1133000003’ 我每次用tstrings来做,,最后再使用listbox.addstrings方法时,总是会错误,我对delphi的调试不是很熟悉!求指点! 做个循环,组合一下 013用replace()函数//参考function Replace(const Pattern, ReplaceText: string; CaseSensitive, RegularExpression, WholeFile: Boolean; Direction: TSearchDirection; var ErrorCode: Integer): Integer; overload; 具体要求没弄明白,格式化字符串可用如下方式Format( '11%.2d22', [1] ) 算法有点小复杂啊。给你个完整代码吧,记得结贴给分。窗口一个edit控件,用来输入字符串,可以输任何,只替换‘#’,一个按钮,一个listbox.unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; ListBox1: TListBox; Edit1: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } arr: array of string; procedure replacestr(str: string); end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.replacestr(str: string);var I: Integer; Nstr: string;begin for I := 1 to length(str) do begin if str[I] = '#' then begin setlength(arr, length(arr)+1); arr[length(arr) - 1] := copy(str,1,I-1) + '0'+ copy(str,I+1,length(str)-I); Nstr := arr[length(arr) - 1]; replacestr(nstr); setlength(arr, length(arr)+1); arr[length(arr) - 1] := copy(str,1,I-1) + '1'+ copy(str,I+1,length(str)-I); Nstr := arr[length(arr) - 1]; replacestr(nstr); setlength(arr, length(arr)+1); arr[length(arr) - 1] := copy(str,1,I-1) + '3'+ copy(str,I+1,length(str)-I); Nstr := arr[length(arr) - 1]; replacestr(nstr); break; end; end;end;procedure TForm1.Button1Click(Sender: TObject);var I: integer;begin replacestr(Edit1.Text); for I := 0 to length(arr) - 1 do begin if pos('#', arr[I]) = 0 then ListBox1.Items.Add(arr[I]); end;end;end. fontdialog被窗口挡住无法操作 请问这个错误怎样处理EVariantTypeCastError? odac的数据表更新问题 这是怎么回事啊?高手请进[悬赏100分] TOleContainer读入ppt文件,如何让它播放? 我用ADO+access执行update或insert的时候,总是报错请问何故? indy批量传输文件 如何生成拖离delphi环境的可执行文件 开工大半了给别人,心有不服! 请教各位把中文转换成ascii码的函数.60分送上. Field XXX cannot be modified 如何读取ini文件
可以使用stringreplace函数将#替换成相应字符串
就是要转化为‘1133000003’‘1133000103’‘1133000303’
‘1133001#03’‘1133001003’‘1133001303’
‘1133003003’‘1133003103’‘1133000003’
用replace()函数//参考
function Replace(const Pattern, ReplaceText: string; CaseSensitive, RegularExpression, WholeFile: Boolean; Direction: TSearchDirection; var ErrorCode: Integer): Integer; overload;
Format( '11%.2d22', [1] )
窗口一个edit控件,用来输入字符串,可以输任何,只替换‘#’,一个按钮,一个listbox.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
arr: array of string;
procedure replacestr(str: string); end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.replacestr(str: string);
var I: Integer;
Nstr: string;
begin
for I := 1 to length(str) do
begin
if str[I] = '#' then
begin
setlength(arr, length(arr)+1);
arr[length(arr) - 1] := copy(str,1,I-1) + '0'+ copy(str,I+1,length(str)-I);
Nstr := arr[length(arr) - 1];
replacestr(nstr);
setlength(arr, length(arr)+1);
arr[length(arr) - 1] := copy(str,1,I-1) + '1'+ copy(str,I+1,length(str)-I);
Nstr := arr[length(arr) - 1];
replacestr(nstr);
setlength(arr, length(arr)+1);
arr[length(arr) - 1] := copy(str,1,I-1) + '3'+ copy(str,I+1,length(str)-I);
Nstr := arr[length(arr) - 1];
replacestr(nstr);
break;
end;
end;end;procedure TForm1.Button1Click(Sender: TObject);
var
I: integer;
begin
replacestr(Edit1.Text);
for I := 0 to length(arr) - 1 do
begin
if pos('#', arr[I]) = 0 then
ListBox1.Items.Add(arr[I]);
end;
end;end.