在一條字符串中有多個空格
怎样取第三个到第四个空格之间的字符串
var
i,k,m,n:integer;
str:string;
begin
str:=trim(listbox1.Items[0]);
for i:=1 to Length(str) do
begin
if str[i]=' ' then
begin
k:=K+1;
if K=6 then
begin
m:=i;
end;
if K=8 then
begin
n:=i;
end;
end;
end;
showmessage(copy(listbox1.Items[0],m,n-m));
为什么这样得到的是整个字符串
在最后加上以下代码这OK了
showmessage(inttostr(n));
怎样取第三个到第四个空格之间的字符串
var
i,k,m,n:integer;
str:string;
begin
str:=trim(listbox1.Items[0]);
for i:=1 to Length(str) do
begin
if str[i]=' ' then
begin
k:=K+1;
if K=6 then
begin
m:=i;
end;
if K=8 then
begin
n:=i;
end;
end;
end;
showmessage(copy(listbox1.Items[0],m,n-m));
为什么这样得到的是整个字符串
在最后加上以下代码这OK了
showmessage(inttostr(n));
解决方案 »
- 数据写入的问题
- 下载了一个QUICKREPORT4.05,请问怎样安装到delphi里呢
- 如何用程序实现启动/停止局域网内其它机器上的SQL Server 服务器?
- 如何让程序自动打开自己
- delphi中的字符串替换函数是什么,在线等
- 联想数码相机Show303驱动程序太烂!
- 在Delphi6.0三层结构中如果设置了Params然后客户端不能用中文查询???
- 用d5如何考贝一个目录以及其所在目录的所有子文件及文件平一同copy
- 为何没有DBExpree组件板 ?
- MenuItem的caption属性会自动加入一个&...
- 关于字段解密的问题!
- 怎么将ClientDataSet的一条纪录,向上或向下挪几条?
function GetBlockStr(s:String;n:integer;BlockChar:char):String;
var loc:integer;
begin
Loc:=pos(BlockChar,s);
if Loc=0 then
if n=1 then Result:=s else Result:=''
else
if n=1 then
Result:=Copy(s,1,loc-1)
else
Result:=GetBlockStr(copy(s,loc+1,length(s)-loc),n-1,BlockChar);
end;然后
getblockstr( 你的字符串,4,' ') 就是你要的东西. // ' '是一个空格
var
i,k,m,n:integer;
str:string;
begin
k:=0;
str:=trim('123 4 5 6 7 89 999');
for i:=1 to Length(str) do
begin
if str[i]=' ' then
begin
k:=K+1;
if K=3 then m:=i;
if K=4 then n:=i;
end;
end;
showmessage(copy(str,m,n-m));
var
i,k,m,n:integer;
str:string;
begin
str:=trim(listbox1.Items[0]);
k:=0 ; //加上这个
for i:=1 to Length(str) do
begin if str[i]=' ' then
begin
k:=K+1;
if K=3 then
begin
m:=i;
end;
if K=4 then
begin
n:=i;
end;
end;
end;
showmessage(copy(listbox1.Items[0],m,n-m));
end;
i,k,m,n:integer;
str:string;
begin
str:=trim(listbox1.Items[0]);
for i:=1 to Length(str) do
begin
if str[i]=' ' then
begin
k:=K+1;
if K=3 then
begin
m:=i;
end;
if K=4 then
begin
n:=i;
end;
end;
end;
showmessage(copy(str,m,n-m+1));