这里有个循环
一个Memo 一个Listview
Listview 里的数据如下
|a |oldman|asd |4534 |sfsd |asd |2345 |124 |123466 |kdxs
|43 |affd |fdhgf |dfhfh |sdggg |4364 |sfsdf |sdf |34645 |fse
|58 |boy |asd |4538 |sfsd |asd |2345 |124 |123466 |kdxs
Memo 里的数据如下
{.oldman.} :*\/*~*~+/man\+
{.boy.} :*\/*~*~+/girl\+
-----------
怎么样能够循环memo取 {.到.}里的内容 和 +/到\+里的内容
并且查找listview里每一条的第2列
是否含有 {.到.}的内容
找到含有 {.到.}的内容的那一条后修改它的第五列使他显示+/到\+里的内容
[解决办法]
var
Str, Str2, Str5: string
sIndex, eIndex: Integer;
Str := '{.oldman.} :*\/*~*~+/man\+ ';
// 取{.到.}的内容之间的内容
sIndex := Pos( '{. ', str);
eIndex := Pos( '.} ', str);
if (sIndex > 0) and (eIndex > 0) and (sIndex + 2 <= eIndex ) then
Str2 := copy(str, sIndex + 2, eIndex - sIndex - 2);
// 去+/到\+之间的内容
sIndex := Pos( '+/ ', str);
eIndex := Pos( '\+ ', str);
if (sIndex > 0) and (eIndex > 0) and (sIndex + 2 <= eIndex ) then
Str5 := copy(str, sIndex + 2, eIndex - sIndex - 2);
// 替代listview中的内容
for I := 0 to listview.items.count - 1 do
begin
// listview第二列就是listitem的subitems[0],第五列就是listitem的subitems[3]
if Listview.Items.Item[I].subitems[0] = str2 then
Listview.Items.Item[I].subitems[3] := Str5;
end;