|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 qq351317878 于 2014-10-15 18:18 编辑
分割已一行为单位 ,可同时分割多行
以逗号为分割标志
(源码可以自己修改)
源码献上 界面,源码和我人一样丑 所以轻喷
http://pan.baidu.com/s/1dDvjR49
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- TForm1 = class(TForm)
- Memo1: TMemo;
- Memo2: TMemo;
- Memo3: TMemo;
- Memo4: TMemo;
- Memo5: TMemo;
- Memo6: TMemo;
- Button1: TButton;
- Label1: TLabel;
- procedure Button1Click(Sender: TObject);
- function mysplit(Source, Deli: string ): TStringList; stdcall;
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.Button1Click(Sender: TObject);
- var
- j,i,memocount:Integer;
- s:string ;
- constr:TStringList;
- begin
- Memo2.Clear;
- Memo3.Clear;
- Memo4.Clear;
- Memo5.Clear;
- Memo6.Clear;
- memocount:= Memo1.Lines.Count ;
- for i:= 0 to memocount do
- begin
- s:=Memo1.Lines.Strings[i];
- s:=StringReplace (s, ',', ',', [rfReplaceAll]); //转换全角
- if Length(Trim(s)) <> 0 then
- begin
- constr :=TStringList.Create;
- constr:= mysplit(s,','); //分割文本
- if constr.Count = 5 then
- begin
- Memo2.Lines.Add(constr[0]);
- Memo3.Lines.Add(constr[1]);
- Memo4.Lines.Add(constr[2]);
- Memo5.Lines.Add(constr[3]) ;
- Memo6.Lines.Add(constr[4]) ;
- end;
-
- end;
- end;
- Label1.Caption := + IntToStr(Memo1.Lines .Count - Memo2.Lines.Count )+'处分割失败';
- end;
- function tform1.mysplit (Source, Deli: string ): TStringList; stdcall; //分割函数
- var
- EndOfCurrentString: byte;
- StringList:TStringList;
- begin
- StringList:=TStringList.Create;
- while Pos(Deli, Source)>0 do
- begin
- EndOfCurrentString := Pos(Deli, Source);
- StringList.add(Copy(Source, 1, EndOfCurrentString - 1));
- Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) - EndOfCurrentString);
- end;
- Result := StringList;
- StringList.Add(source);
- end;
- end.
- end;
- function tform1.mysplit (Source, Deli: string ): TStringList; stdcall;
- var
- EndOfCurrentString: byte;
- StringList:TStringList;
- begin
- StringList:=TStringList.Create;
- while Pos(Deli, Source)>0 do
- begin
- EndOfCurrentString := Pos(Deli, Source);
- StringList.add(Copy(Source, 1, EndOfCurrentString - 1));
- Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) - EndOfCurrentString);
- end;
- Result := StringList;
- StringList.Add(source);
- end;
- end.
复制代码
|
|