案例

给定一个字符串,为多个单字符串连接而成,单个字符串格式为 bm(num,price)

以以下详细字符串演示:

‘20151202142400000002(2,0)20151202142200000001(1,4)’

要求

取出20151202142200000001(1,4)括号内的1和4.

直接上干货

var
    i,j,k,m:integer;
  str:='20151202142400000002(2,0)20151202142200000001(1,4)';
  mstr:='20151202142200000001';
  for i:=Pos(mstr,str)+length(mstr) to length(str) do
  begin
    j:=0;
    k:=0;
    m:=0;
    if str[i]='(' then
    begin
        j=i;
    end
    else if str[i]=',' then
    begin
        k=i;
    end
    else if str[i]=')' then
    begin
        m=i;
    end;
    if (right_bracket>comma) and (comma>left_bracket) then
       break;

  end;
  pro_num:=midstr(str,j+1,k-j-1);
  pro_price:=midstr(str,k+1,m-k-1);

以上为个人总结。如有不妥之处,请在评论中指出。