我现在要读取一个固定格式的.txt文本内容,然后写入到数据库中。但是当我根据字符的长度选择性写入到数据库时,总是出现长度的计算错误。
例如我判断‘你’和‘ni’时,应该长度为2。但是我的代码中显示的是‘?’和‘ni’就成了长度为1和2了。
delphi重新装了,还是不行……
例如我判断‘你’和‘ni’时,应该长度为2。但是我的代码中显示的是‘?’和‘ni’就成了长度为1和2了。
delphi重新装了,还是不行……
解决方案 »
- 赋值刷新显示问题
- 救命呀!俺笨,请各位江湖好汉多多相助!关于ftp端口的问题!
- access中支持下面的語句嗎
- 我想在软件中使用EhLib组件,不知它是不是免费的?有没有什么限制?
- 为什么Max()不能取得最大值?
- access+ado 存像如何存入数据库中?
- 如何得到网页上的全部链接和名称?
- 用application打开.doc文档时,能否在程序中就地把它转成rtf格式???
- LINUX下C++怎么进行ORACLE数据库编程---急!!(傻傻的问)
- 怎样将jpg文件转换为bmp文件?
- delphi连mysql怎样才不用配制odbc,或bde
- 急问如何用ADOCONNECTION连接INTERNET上的数据库服务器?
Address:=trim(Midstr(str1,11,50));
Company:=trim(Midstr(str1,61,50));
UserName:=trim(Midstr(str1,111,20));
txt文本中显示的字体是‘宋体’,但是原样拷到代码区就不显示了。
大家帮帮啊,分不够可以再加。千万不要因此让我对Delphi失去了信心啊。
unit GetInfo;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, DB, ADODB,StrUtils;type
TFrmGetInfo = class(TForm)
Btn_GetInfo: TBitBtn;
ADOTable1: TADOTable;
Button1: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
ListBox3: TListBox;
Memo1: TMemo;
procedure Btn_GetInfoClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
FrmGetInfo: TFrmGetInfo;implementation{$R *.dfm}procedure TFrmGetInfo.Btn_GetInfoClick(Sender: TObject);
var
logfile:TextFile;
logbak:TextFile;
Str1:widestring;
BatFile,TxtFile:wideString;
UserName,Company,Address,Postalcode,B1,network:widestring;
begin
BatFile:=ExtractFilePath(Paramstr(0))+'post.bat';//»ñÈ¡post.batµÄ·¾¶
TxtFile:=ExtractFilePath(Paramstr(0))+'Post.txt';//»ñÈ¡post.txtµÄ·¾¶
AssignFile(logbak,BatFile);
if not FileExists(BatFile)then
Rewrite(logbak)
else
Append(logbak);
if not FileExists(BatFile)then
MessageDlg('Ä¿±êÎļþ²»´æÔÚ£¡',mtInformation,[mbOk],0)
else
begin
AssignFile(logfile,'post.txt');
Reset(logfile);
if Eof(logfile) then
begin
ShowMessage('ÈÕÖ¾Îļþ²»´æÔÚ£¡');
Exit;
end;
end;
//¶ÁÈ¡Îı¾ÄÚÈÝ£¬²¢Ð´Èëµ½Êý¾Ý¿âÖÐ
memo1.Clear;
while not Eof(logfile) do
begin
Readln(logfile,Str1);
Writeln(logbak,str1);
Postalcode:=trim(leftStr(str1,10));
Address:=trim(AnsiMidstr(str1,11,50));
Company:=trim(AnsiMidstr(str1,61,50));
UserName:=trim(AnsiMidstr(str1,111,20));
B1:=trim(AnsiMidstr(str1,131,10));
network:=trim(Ansirightstr(str1,10));
listbox1.Items.Add(username);
listbox2.Items.Add(address);
listbox3.Items.Add(company);
with adotable1 do
begin
TableName:='UserInfo';
Open;
try
begin
Append;
FieldByName('UserName').Value:=UserName;
FieldByName('Postalcode').Value:=Postalcode;
FieldByName('Address').Value:=Address;
FieldByName('Company').Value:=Company;
FieldByName('B1').Value:=B1;
FieldByName('network').Value:=network;
post;
end;//try
except
cancel;
end;//try...except
end;//with }
memo1.Lines.Add(str1);
end; //while
CloseFile(logfile);
CloseFile(logbak);
ShowMessage('³É¹¦¶ÁÈ¡ËùÓÐÊý¾Ý£¡');
end;procedure TFrmGetInfo.FormCreate(Sender: TObject);
begin
adoTable1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractFilePath(Paramstr(0))+'UserInfo.mdb'+';Persist Security Info=False'
end;
end.
我text内容是‘大家好我是阿杜,你叫什么名字啊,我也叫阿杜,啊,,怎么搞啊,什么意思啊’
最后显示结果是“家好我是”,没什么出错啊
procedure TForm1.Button1Click(Sender: TObject);
var
LogFile:TextFile;
TempStr:WideString;
UserName,Company,Address,Postalcode:widestring;
begin
AssignFile(LogFile,'c:\test.txt');
Reset(LogFile);
try
while not eof(LogFile) do
begin
ReadLn(logFile,Tempstr);
end;
Finally
CloseFile(logFile);
end;
Postalcode:=trim(leftStr(tempstr,1));
Address:=trim(AnsiMidstr(tempstr,2,4));
Company:=trim(AnsiMidstr(tempstr,6,10));
UserName:=trim(AnsiMidstr(tempstr,111,20));
showmessage(address);
end;