数控程序中对字段的操作

一、删除注释

删除所有括号中的内容。

function DelComment(S: String): String;
var
  left, bCount, i: Longint;
begin
  bCount:= 0;
  i:= 1;
  while i <= Length(S) do
  begin
    if S[i] = ( then
    begin
      if bCount = 0 then
        left:= i;
      inc(bCount);
    end;
    if S[i] = ) then
    begin
      if bCount = 1 then
      begin
        Delete(S,left,i-left+1);
        i:= left-1;
      end;
      dec(bCount);
    end;
    inc(i);
  end;
  Result:= S;
end;

 

二、读取字段

读取指定字母的字段。

function GetBlock(S: String; A: Char; var Value: Real): String;
var
  i,p: Integer;
begin
  S:= DelComment(S);

  GetBlock:=‘‘;
  Value:= 0;
  p:=Pos(A,S);
  if p>0 then
  begin
    i:=p;
    Repeat
      inc(i);
    Until (i>Length(s)) or (S[i] in [A..Z]);
    S:= Trim(Copy(S,p,i-p));
    GetBlock:= S;
    Value:= StrToFloat(Copy(S),2,maxint));
  end;
end;

 

三、更改字段

改变字段的值。

procedure ChangeBlock(var S: String; A: Char; Value: Real);
var
  i,p: Integer;
begin
  S:= DelCommnet(S);

  p:= Pos(A,S);
  if p>0 then
  begin
    i:=p;
    Repeat
      inc(i);
    Until (i>Length(s)) or (S[i] in [A..Z]);
    if i<Length(S)
    then S:= Copy(S,1,p-1)+A+FormatNum(Value)+ +Copy(S,i,maxint)
    else S:= Copy(S,1,p-1)+A+FormatNum(Value);
  end;
end;

 

数控程序中对字段的操作

上一篇:HDOJ2503 ( a/b + c/d ) 【最大公约数GCD,最小公倍数LCM】


下一篇:Swagger使用