原贴出在 http://bbs.2ccc.com/topic.asp?topicid=142013 要用到 StringReplace,请uses strUtils.const OldPattern=''''; NewPattern=''''''; var txtFile:TextFile; strTxt:string; strErrHandle,strHelpRes,strS:string; intLen,intAtSignPos:Integer; begin if dlgOpen1.Execute then begin AssignFile(txtFile,dlgOpen1.FileName); Reset(txtFile); redt1.Font.Size:=10; redt1.Clear; while not Eof(txtFile) do begin Readln(txtfile,strtxt); strS:=StringReplace(strTxt,OldPattern,NewPattern,[rfReplaceAll]); intLen:=Length(strS); intAtSignPos:=pos('@',strS); strErrHandle:=LeftBStr(strS,intAtSignPos-1); strHelpRes:=RightBStr(strS,intLen-intAtSignPos); with qry1 do begin Close; SQL.Clear; SQL.Add('INSERT INTO TEST1 (DESR,TEST) VALUES '); SQL.Add('('''+ strErrHandle +''',''' + strHelpRes+''')'); ExecSQL; //ShowMessage(SQL.Text); end; //ShowMessage(strErrHandle); //ShowMessage(strHelpRes); end; CloseFile(txtFile); end; end;
要用到 StringReplace,请uses strUtils.const
OldPattern='''';
NewPattern='''''';
var
txtFile:TextFile;
strTxt:string;
strErrHandle,strHelpRes,strS:string;
intLen,intAtSignPos:Integer;
begin
if dlgOpen1.Execute then
begin
AssignFile(txtFile,dlgOpen1.FileName);
Reset(txtFile);
redt1.Font.Size:=10;
redt1.Clear;
while not Eof(txtFile) do
begin
Readln(txtfile,strtxt);
strS:=StringReplace(strTxt,OldPattern,NewPattern,[rfReplaceAll]);
intLen:=Length(strS);
intAtSignPos:=pos('@',strS);
strErrHandle:=LeftBStr(strS,intAtSignPos-1);
strHelpRes:=RightBStr(strS,intLen-intAtSignPos);
with qry1 do
begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO TEST1 (DESR,TEST) VALUES ');
SQL.Add('('''+ strErrHandle +''',''' + strHelpRes+''')');
ExecSQL;
//ShowMessage(SQL.Text);
end;
//ShowMessage(strErrHandle);
//ShowMessage(strHelpRes);
end;
CloseFile(txtFile);
end;
end;
只有用替换的方法,把'替换为:''