【问题标题】:How can I insert a space character in every upper case letter expect the first one at each element of string array in DXL script?如何在每个大写字母中插入一个空格字符,除了 DXL 脚本中字符串数组的每个元素的第一个字符?
【发布时间】:2018-08-01 16:19:44
【问题描述】:

我想用 for 循环中使用的 DXL 脚本编辑字符串数组的元素。该问题将在下面描述: 我想在每个大写字母前面插入空格,除了第一个,它将应用于字符串数组中的所有行。

例子:

有一个字符串数组:

AbcDefGhi

GhiDefAbc

DefGhiAbc

等等

最后我希望看到的结果是:

Abc Def Ghi

Ghi Def Abc

Def Ghi Abc

等等

提前致谢!

【问题讨论】:

    标签: ibm-doors


    【解决方案1】:

    直接来自 DXL 手册..

    Regexp upperChar  = regexp2 "[A-Z]"
    string s = "yoHelloUrban"
    
    string sNew = ""
    while (upperChar s) {
       sNew = sNew s[ 0 : (start 0) - 1] " " s [match 0]
       s = s[end 0 + 1:]
    }
    sNew = sNew s
    print sNew
    

    您可能需要调整一个事实,即您不希望每个大写字母都被替换为 ,只有那些不在字符串开头的字母。

    【讨论】:

      【解决方案2】:

      这是一个编写为函数的解决方案,您可以直接放入代码中。它逐个字符地处理输入字符串。始终按原样输出第一个字符,然后在任何后续大写字符之前插入一个空格。

      为了提高效率,如果处理大量字符串或非常大的字符串(或两者兼有!),可以修改函数以追加到缓冲区而不是字符串,然后最终返回字符串。

      string spaceOut(string sInput)
      {
          const int intA = 65 // DECIMAL 65 = ASCII 'A'
          const int intZ = 90 // DECIMAL 90 = ASCII 'Z'
      
          int intStrLength = length(sInput)
          int iCharCounter = 0
      
          string sReturn = ""
      
          sReturn = sReturn sInput[0] ""
      
          for (iCharCounter = 1; iCharCounter < intStrLength; iCharCounter++)
          {
              if ((intOf(sInput[iCharCounter]) >= intA)&&(intOf(sInput[iCharCounter]) <= intZ))
              {
                  sReturn = sReturn " " sInput[iCharCounter] ""
              }
              else
              {
                  sReturn = sReturn sInput[iCharCounter] ""
              }
          }
      
          return(sReturn)
      }
      
      print(spaceOut("AbcDefGHi"))
      

      【讨论】:

        猜你喜欢
        • 2023-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-23
        • 1970-01-01
        • 2012-05-19
        • 2010-12-25
        • 1970-01-01
        相关资源
        最近更新 更多