Separate out a pascal-case string

I have an integration which makes a POST (read-only) to a database. The returned value is a string formatted in pascal-case.

There are a total of 25 possible string value responses, here are some examples from the 25 possibilities:

"DeferredStudentLoan"

"LeasePayment"

"PersonalLoan"

I need to convert these strings from the above pascal-case to standard-case (I guess you call it that?).

"DeferredStudentLoan" should be converted to "Deferred Student Loan"

"LeasePayment" should be converted to "Lease Payment"

"PersonalLoan" should be converted to "Personal Loan"

Here are some snippets of code...

a!localVariables(
  local!line4_addedLines: 1,
  local!PostCall: rule!EI_FieldReader_CDpg3_UCD_Sec_K_Line4(),
  
  ........

local!PostCall: rule!EI_FieldReader_CDpg3_UCD_Sec_K_Line4() creates a dictionary of the post call made in the integration (not shown anywhere in this thread). 

I call upon a specific result from the dictionary using this example code (refer to 'value').

a!sideBySideItem(
                            item: a!richTextDisplayField(
                              label: "Adjustment Type",
                              labelPosition: "ABOVE",
                              value: {index(local!PostCall.result.body.value,10)}
                            )
                          )

'value' returns one of the pascal-case strings from up top. This is the value I need to convert.

Thanks for your time!

Mica

  Discussion posts and replies are publicly visible

Parents
  • This is a good use case for the code() function to determine case of each character.  When you find an upper case, insert a space.  I would recommend creating a rule that converts each value such as below, then call the rule over your values to convert:

    a!localVariables(
      local!data: "DeferredStudentLoan",
      
      joinarray(
        a!forEach(
          items: 1+enumerate(len(local!data)),
          expression: a!localVariables(
            local!char: charat(local!data,fv!index),
            if(
              or(
                fv!isFirst,
                code(charat(local!data,fv!index))>96
              ),
              local!char,
              {" ",local!char}
            )
          )
        )
      )
    )

  • I can only sort of understand this code. Would I need to create a local variable for each possibility? 

  • 0
    Certified Lead Developer
    in reply to Micamack

    Chris's code (or my example or any of the other various examples at the prior thread I linked) should work for whatever string you want to pass into it.  Here Chris has hardcoded the local variable to an example string, but when you do it for real you'd simply set the local variable to hold the output of the integration where you get your ProperCamelCase string returned.

  • Thanks to the both of you. I just went and looked at that other thread as well. Tons of information - wish I found that thread before bothering both of yall!

  • Yes, this example is built as a self-containing snippet so you can simply copy/paste into a New Rule and see it run.  In your environment, create a rule with whatever name you want and a ri!data (text) input as:

    joinarray( /* combine the array into a string */
      a!forEach(
        items: 1+enumerate(len(ri!data)), /* 1 item for each character */
        expression: a!localVariables(
          local!char: charat(ri!data,fv!index), /* retrieve the character at this index */
          if(
            or(
              fv!isFirst, /* first character, do not add a leading space */
              code(charat(ri!data,fv!index))>96 /* unicode value for this character, lowercase a-z are 97-122, upper case A-Z are 65-90 */
            ),
            local!char, /* add current character only */
            {" ",local!char} /* upper case detected, return a space and this character */
          )
        )
      )
    )

Reply
  • Yes, this example is built as a self-containing snippet so you can simply copy/paste into a New Rule and see it run.  In your environment, create a rule with whatever name you want and a ri!data (text) input as:

    joinarray( /* combine the array into a string */
      a!forEach(
        items: 1+enumerate(len(ri!data)), /* 1 item for each character */
        expression: a!localVariables(
          local!char: charat(ri!data,fv!index), /* retrieve the character at this index */
          if(
            or(
              fv!isFirst, /* first character, do not add a leading space */
              code(charat(ri!data,fv!index))>96 /* unicode value for this character, lowercase a-z are 97-122, upper case A-Z are 65-90 */
            ),
            local!char, /* add current character only */
            {" ",local!char} /* upper case detected, return a space and this character */
          )
        )
      )
    )

Children
No Data