还是没有解决啊.(50分)

  • 主题发起人 主题发起人 tiger_520
  • 开始时间 开始时间
T

tiger_520

Unregistered / Unconfirmed
GUEST, unregistred user!
{Type=0~Id= 153~Name=胆囊长径~Text=胆囊长径~Unit=mm~Value=52} ,{Type=0~Id= 154~Name=胆囊前后径~Text=前后径~Unit=mm~Value=18} ,{Type=0~Id= 71~Name=胆囊壁厚~Text=胆囊壁厚~Unit=mm~Value=7}。胆囊大小、形态正常,胆囊壁不光滑,胆囊腔内可见多个强回声光团,{Type=0~Id= 566~Name=最大~Text=最大~Unit=mm~Value=6*6},后伴声影,可移动.

要达到的效果是这样子:
胆囊长径52mm ,胆囊前后径18mm ,胆囊壁厚7mm。胆囊大小、形态正常,胆囊壁不光滑,胆囊腔内可见多个强回声光团,最大6*6mm,后伴声影,可移动.

该如何编写代码才能达到这个效果,注意的是Id=后头的数字位数,Name=和Unit=的字符位数是不定的.急啊,高手们都来看啊
 
//子函数,从{}中取得名称或值或单位
function TForm1.GetSubStr(const Sour, Key, Separate: string): string;
var
tmpstr: string;
begin
Result := '';
if Pos(Key, Sour) > 0 then
begin
tmpstr := Copy(Sour, Pos(Key, Sour) + Length(Key), Length(Sour));
if Pos(Separate, tmpstr) > 0 then
Result := Copy(tmpstr, 1, Pos(Separate, tmpstr) - 1)
else
Result := tmpstr;
end;
end;

procedure GetString(const inVal, var outVal: string);
const
sName = 'Name=';
sUnit = 'Unit=';
sValue = 'Value=';
sSeparate = '~';
var
inVal, outVal: string;
pPos, midStr, tmpstr: string;
iPos: integer;
begin
outVal := '';
pPos := inVal;
iPos := Pos('{', pPos);
if iPos <= 0 then
begin
outVal := inVal;
Exit;
end;
while (iPos > 0) do
begin
outVal := outVal + Copy(pPos, 0, iPos - 1);
pPos := Copy(pPos, iPos + 1, Length(pPos));
if Pos('}', pPos) > 0 then
begin
midStr := Copy(pPos, 1, Pos('}', pPos) - 1);

outVal := outVal + GetSubStr(midStr, sName, sSeparate);
outVal := outVal + GetSubStr(midStr, sValue, sSeparate);
outVal := outVal + GetSubStr(midstr, sUnit, sSeparate);

pPos := Copy(pPos, Pos('}', pPos) + 1, Length(pPos));
iPos := Pos('{', pPos);
end
else
ShowMessage('Illegal Input String');
end;
if Length(pPos) > 0 then
outval := outVal + pPos;
end;
 
接受答案了.
 
后退
顶部