Skip to main content
hemantb0002
Known Participant
October 29, 2021
Question

want to convert "indiaChinaFrance" to "India China France"

  • October 29, 2021
  • 14 replies
  • 0 views

want to display dynamic field name on screen but with updating initial as capital and adding one space in between.Field name always start with small caps

eg. "indiaChinaFrance" to "India China France"

eg. abcDefXyz to "Abc Def Xyz"

    14 replies

    stewart.burchell
    October 29, 2021

    I'm sure there are easier ways (awaits others to gleefully provide simpler solutions) but here's my offering:

    a!localVariables(
      local!items: { "A", "B", "C", "D", "E", "F" },
      local!splitAttribute: fn!reduce(fn!split, ri!attributeName, local!items),
      a!forEach(
        items: local!splitAttribute,
        expression: if(
          fv!isFirst,
          fn!proper(fv!item),
          fn!concat(
            ri!attributeName[fn!find(fv!item, ri!attributeName, 1) - 1],
            fv!item
          )
        )
      )
    )

    The idea is to have the full set of characters that you want to use as delimiters in the string you want to process (I've only provide A-F as an example).

    You then split the incoming string based upon that list. Unfortunately (j this instance) the split function excludes the value you're splitting, so you up wiht a list where the first item is whole but the remaining items are missing their first character. 

    The aim of the remainder of the code is to re-append the missing character to each item in the list generated by the split processing.

    hemantb0002
    Known Participant
    October 29, 2021

    @stewart.burchell let me try

    stefanhelzle0001
    Brainy
    October 30, 2021

    Could not hold me back. My looping function solution.I am sure Mike will love it ;-)

    a!localVariables(
      local!input: "indiaChinaFrance",
      proper(
        reduce(
          substitute(_, _, _),
          local!input,
          merge(
            char(65+enumerate(26)),
            apply(concat(" ", _), char(65+enumerate(26)))
          )
        )
      )
    )

    richardm900458
    October 31, 2021

    Stefaaaaaan [emoticon:d6dd260102fd406884fc96b8bc59760b]  I am not mike, but  I remember during our last call I mentioned the factor of maintainability regarding coding :D
    perhaps that is the most elegant way of all the above, but absolutly hell for people who shall maintain that.  "reduce" in combination of merge and on top (multiple) "_" is definitly not inituive to read.... [emoticon:44a8a53ad3364ea78a16c5a3229f75bb]

    csteward
    November 1, 2021

    #JobSecurity [emoticon:752f32bcc91d4a448db162742a877a4a]

    It is a beautiful piece of code though!  Not sure I even knew the proper() function existed until now..

    Might as well include my solution here also [emoticon:c4563cd7d5574777a71c318021cbbcc8]

    a!localVariables(
      local!input: "indiaChinaFrance",
      joinarray(
        a!forEach(
          items: enumerate(len(local!input)),
          expression: a!localVariables(
            local!char: charat(local!input,fv!index),
            if(
              fv!isFirst,
              upper(local!char),
              if(
                code(local!char)<97,
                concat(" ",local!char),
                local!char
              )
            )
          )
        )
      )
    )