首页 > 其他 > 详细

数控程序中对字段的操作

时间:2021-09-06 21:50:13      阅读:18      评论:0      收藏:0      [点我收藏+]

一、删除注释

删除所有括号中的内容。

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;

 

数控程序中对字段的操作

原文:https://www.cnblogs.com/Automated/p/15233627.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!