var tls:TStringList; i:Integer;tls:=TStringList.Create; try tls.Text:=StringReplace('RMB39.00,$134.00,¥16.00',',',#13#10); for i:=0 to tls.Count-1 do begin //tls.Strings[i]; //RMB39.00 //$134.00 //¥16.00 //拉下来就可以去掉关导非数字字符了 end; finally tls.Free; end;
如何找到第一个数字的位置啊?找到第一个数字的位置就可以 ///////////////////////// 方法2加上一个循环就可以 /////////////////////////// procedure TForm1.Button1Click(Sender: TObject); var temp:string; I,J,position:integer; begin temp:='RMB39.00'; for I:=1 to length(temp) do begin if TryStrToInt(temp[I],J) then begin position:=I; break; end; end; showmessage(rightstr(temp,length(temp)-position+1)); end;
给你两个随便用!呵呵! 先用flag := ',' 分割 if 是美圆 then edit1.text:=copy('rmb39.00',4,length('rmb39.00')-3); if 是英镑 then edit2.text:=copy('$134.00',2,length('rmb39.00')-1); if 是人民币 then edit3.text:=copy('¥16.00',2,length('¥16.00')-1); //从source中截取一flag为分隔符的字串 function SplitStringA(const source, flag: string): Tstringlist; var ts: Tstringlist; begin if Trim(source) <> '' then begin ts := Tstringlist.create; ts.Delimiter := flag[1]; ts.DelimitedText := source; Result := ts; end; end;function SplitString(const source, flag: string): Tstringlist; var temp: string; i: integer; begin if Trim(source) <> '' then begin Result := Tstringlist.create; temp := source; i := pos(flag, source); while i > 0 do begin Result.Add(copy(temp, 0, i - 1)); delete(temp, 1, i); i := pos(flag, temp); end; Result.Add(temp); end else Result.Add(''); end;
例如:unit Unit1;'Powered by Jadeluo, 2005/05/30interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); public procedure SplitValue(sMoney: String; var sKind, sValue: String); end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.SplitValue(sMoney: String; var sKind, sValue: String); var iLoop : Integer; begin sKind := sMoney; sValue := ''; for iLoop := 1 to length(sMoney) do begin if (copy(sMoney, iLoop, 1) >= '0') and (copy(sMoney, iLoop, 1) <= '9') then begin sKind := copy(sMoney, 1, iLoop - 1); sValue := copy(sMoney, iLoop, length(sMoney) - iLoop + 1); break; end; end; end;procedure TForm1.FormCreate(Sender: TObject); var sKind, sValue : String; begin SplitValue ('RMB39.00', sKind, sValue); ShowMessage (sKind + ' ' + sValue); SplitValue ('$134.00', sKind, sValue); ShowMessage (sKind + ' ' + sValue); SplitValue ('¥16.00', sKind, sValue); ShowMessage (sKind + ' ' + sValue); end;end.
var s,t:string; i:integer; begin for i:=1 to length(s) do begin if s[i] in ['0'..'9','.'] then t:=t+s[i]; end; showmessage(t); end;
var s,t:string; i:integer; begin for i:=1 to length(s) do begin if s[i] in ['0'..'9','.'] then t:=t+s[i]; end; showmessage(t); end; 我也同意楼上的看法
edit2.text:=copy('$134.00',2,length('rmb39.00')-1);
edit3.text:=copy('¥16.00',2,length('¥16.00')-1);
tls:TStringList;
i:Integer;tls:=TStringList.Create;
try tls.Text:=StringReplace('RMB39.00,$134.00,¥16.00',',',#13#10);
for i:=0 to tls.Count-1 do
begin
//tls.Strings[i];
//RMB39.00
//$134.00
//¥16.00
//拉下来就可以去掉关导非数字字符了
end;
finally
tls.Free;
end;
2、用TryStrToInt可以判断出是否数字,知道了这个也就好处理了
3、如果金额都是整数的话(小数点后没有金额),用 fengzhengren(风筝)的方法也是一个不错的选择
//////////////////////////////
以上三种方法搂住任选
i:Integer;
s:String;
begin;
s:='$12356.0123';
i:=1;
while not (s[i] in ['0'..'9']) do inc(i);
s:=copy(s,i,Length(s)-i);
/////////////////////////
方法2加上一个循环就可以
///////////////////////////
procedure TForm1.Button1Click(Sender: TObject);
var temp:string;
I,J,position:integer;
begin
temp:='RMB39.00';
for I:=1 to length(temp) do
begin
if TryStrToInt(temp[I],J) then
begin
position:=I;
break;
end;
end;
showmessage(rightstr(temp,length(temp)-position+1));
end;
先用flag := ',' 分割
if 是美圆 then
edit1.text:=copy('rmb39.00',4,length('rmb39.00')-3);
if 是英镑 then
edit2.text:=copy('$134.00',2,length('rmb39.00')-1);
if 是人民币 then
edit3.text:=copy('¥16.00',2,length('¥16.00')-1);
//从source中截取一flag为分隔符的字串
function SplitStringA(const source, flag: string): Tstringlist;
var
ts: Tstringlist;
begin
if Trim(source) <> '' then begin
ts := Tstringlist.create;
ts.Delimiter := flag[1];
ts.DelimitedText := source;
Result := ts;
end;
end;function SplitString(const source, flag: string): Tstringlist;
var
temp: string;
i: integer;
begin
if Trim(source) <> '' then begin
Result := Tstringlist.create;
temp := source;
i := pos(flag, source);
while i > 0 do begin
Result.Add(copy(temp, 0, i - 1));
delete(temp, 1, i);
i := pos(flag, temp);
end;
Result.Add(temp);
end
else
Result.Add('');
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
public
procedure SplitValue(sMoney: String; var sKind, sValue: String);
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.SplitValue(sMoney: String; var sKind, sValue: String);
var
iLoop : Integer;
begin
sKind := sMoney;
sValue := '';
for iLoop := 1 to length(sMoney) do
begin
if (copy(sMoney, iLoop, 1) >= '0') and (copy(sMoney, iLoop, 1) <= '9') then
begin
sKind := copy(sMoney, 1, iLoop - 1);
sValue := copy(sMoney, iLoop, length(sMoney) - iLoop + 1);
break;
end;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
var
sKind, sValue : String;
begin
SplitValue ('RMB39.00', sKind, sValue);
ShowMessage (sKind + ' ' + sValue); SplitValue ('$134.00', sKind, sValue);
ShowMessage (sKind + ' ' + sValue); SplitValue ('¥16.00', sKind, sValue);
ShowMessage (sKind + ' ' + sValue);
end;end.
i:integer;
begin
for i:=1 to length(s) do
begin
if s[i] in ['0'..'9','.'] then t:=t+s[i];
end;
showmessage(t);
end;
i:integer;
begin
for i:=1 to length(s) do
begin
if s[i] in ['0'..'9','.'] then t:=t+s[i];
end;
showmessage(t);
end;
我也同意楼上的看法