【问题标题】:How to subdivide the contents of a string variable based on a certain symbol in the content of the variable in RPGLE如何根据RPGLE中变量内容中的某个符号细分字符串变量的内容
【发布时间】:2020-06-10 12:47:59
【问题描述】:

假设我在 RPGLE 中有一个字符串变量。变量的内容是“Hi;this;is;Kunal;Roy”。如何根据符号拆分字符串的内容;

我想让值 Hi , this, is , Kunal , Roy 分离并存储在其他变量中。

有人可以建议一种在 rpgle 中实现它的简单方法吗?

【问题讨论】:

    标签: ibm-midrange rpgle rpg


    【解决方案1】:

    RPG 有一个关于拆分字符串的 RFE,您可以投票:

    “新的内置函数 %SPLIT”: http://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=108424

    【讨论】:

      【解决方案2】:

      有很多不同的方法来处理这个问题。一种解决方案是使用 C 函数 strtok 或 strtok_r。您也可以编写自己的程序。

      服务程序 Linked List 和 Arraylist(来自 rpgnextgen.com)都有一个拆分过程,可以拆分字符串并将各个部分存储在列表中。可以在http://iledocs.rpgnextgen.com 找到这两个服务程序的文档。

      **FREE
      
      ctl-opt dftactgrp(*no) actgrp(*caller) bnddir('GLOBAL');
      
      /include 'arraylist/arraylist_h.rpgle'
      
      main();
      *inlr = *on;
      
      
      dcl-proc main;
        dcl-s list pointer;
        dcl-s text varchar(50);
        dcl-s part varchar(50);
      
        text = 'Hi;this;is;Kunal;Roy';
        list = arraylist_split(text);
        part = arraylist_getString(list : 0);
        dsply part;
      
        arraylist_dispose(list);
      end-proc;
      

      您可以使用位于 https://repo.rpgnextgen.com 的 repo 中的包管理器 iPKG 轻松安装这些服务程序。

      【讨论】:

        【解决方案3】:

        这是一个非常好的问题

        你可以定义一个数组来填充,然后循环遍历字符串

        D ArMax           c                    10                                       
        D ArVal           S                   dim(ArMax) like($MyString)                
        
        c                   movel     ';'           $Symbol           1                         
        c                   z-add     1             $Start            3 0                       
        c     *like         define    $Start        $Pos           
        c     *like         define    $Start        @@count        
               $MyString = 'Hi;this;is;Kunal;Roy';                                              
               $pos = %scan($Symbol: $MyString:$start);                                             
               dow $pos > 0;                                                                    
                 @@count = @@count +1;                                                                                                                                                    
                 ArVal(@@Count) = %subst($MyString:$Start:$pos-$Start);                         
                 $start = $pos +1;                                                              
                 $pos = %scan($Symbol: $MyString:$Start);                                           
               enddo;                                                                           
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-11-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-07-11
          • 1970-01-01
          相关资源
          最近更新 更多