Skip to main content
November 17, 2021
Solved

Separate out a pascal-case string

  • November 17, 2021
  • 9 replies
  • 0 views

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

    Best answer by mikes0011

    Funny, someone asked basically the same thing just within the past few weeks.

    9 replies

    mikes0011
    mikes0011Answer
    Brainy
    November 17, 2021

    Funny, someone asked basically the same thing just within the past few weeks.

    The Expression Guru
    micas0001Author
    November 17, 2021

    I tried :( - Spent about 45 minutes google'ing and trying different functions, also read through suggested posts when creating the topic :( haha.

    mikes0011
    Brainy
    November 17, 2021

    I was only able to find that thread (despite its recency) by searching on a keyword I knew I'd used and filtering to just threads I've participated in, so I don't blame you there.

    The Expression Guru
    csteward
    November 17, 2021

    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}
            )
          )
        )
      )
    )

    micas0001Author
    November 17, 2021

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

    mikes0011
    Brainy
    November 17, 2021

    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.

    The Expression Guru