当前位置:首页|资讯

【MATLAB】关于规范后面无空格的自动处理

作者:-何其-发布时间:2024-10-05

【背景】

为了方便套模板编写方案,考虑在插入应用的规范时,通过调用规范数据库来实现插入。数据库的维护交给了学生,而在插入的时候,调用规范插入Word文档后发现存在如下问题

《XXX》(GB39800.1—20205.3)

以上在GB后面应该是有个空格的,但学生在写入规范数据库的时候有的考虑看GB后面的空格,而有的没有,因此,为了解决这个问题,编写了基于MATLAB的插入后的自检代码,发现以下问题的情况时将自动强制在“GB”这种后面强制加一个空格

【代码】

StandardizedCoding = {'GB','GB/T','JT','JTG','JTG/T','AQ','YJ'}; % 后面紧跟着数字的情况

CombinationList ={};CombinationList2 ={};

for mm = 1 : length(  StandardizedCoding )

   ListID = strfind(Word.ActiveDocument.Content.Text, StandardizedCoding{mm});

   if isempty( ListID )== 1;continue;end

   for nn = 1 : length( ListID)

       Word.Selection.Start =  ListID(nn)+length(StandardizedCoding{mm})-1;

       Word.Selection.End =Word.Selection.Start+2; % 假定规范是2位数以上的数字

       if min( isstrprop(  Word.Selection.Range.Text,'digit')) == 1

           CurrentLabel = {strcat(StandardizedCoding{mm},Word.Selection.Range.Text)};

           CombinationList = vertcat(CombinationList,CurrentLabel);

           CurrentLabel = {strcat(StandardizedCoding{mm},32,Word.Selection.Range.Text)};

           CombinationList2 = vertcat(CombinationList2,CurrentLabel);

       else;continue;

       end

   end

end

然后根据CombinationList和CombinationList2进行循环替换即可,替换代码略



Copyright © 2024 aigcdaily.cn  北京智识时代科技有限公司  版权所有  京ICP备2023006237号-1