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
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?
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!
All good! Mike linked the other thread so if people in future have this question again they are twice as likely now to find the answer! =)