Proper() not capitalizing Names with special characters

Certified Associate Developer

Hi All,

I'm not having the desired result when using proper() with words including special characters.  We receive the error when the user's name has special characters. 

EXP)  O'Neal is being saved as O'neal, Aube-Kubel as Aube-kubel, etc.

I need to implement a rule for capitalizing letters after special characters, but not sure how to proceed.  Any assistance is appreciated, thanks!

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    Maybe this works for you.

    I use a regex to find all first characters at word boundaries. The function returns the start and end positions of the matches. Then I increase the start positions by one as it is zero based. 

    I then use reduce() to iterate on the list of start positions to replace that character by its upper case version.

    Any better version is welcome.

    a!localVariables(
      local!texts: {"o'neal", "aube-kubel"},
      a!forEach(
        items: local!texts,
        expression: reduce(
          rule!SSH_Upper(_,_),
          fv!item,
          tointeger(regexsearch("(\b[a-zA-Z](?!\s))", fv!item, "gms", false).startPosition) + 1
        )
      )
    )

    My helper expression:

    fn!replace(ri!string, ri!index, 1, upper(ri!string[ri!index]))

  • As another option with OOTB functions, you can create your own expression rule that determines which characters should be translated to upper case.  In this example, we maintain a list of characters that determine that the following character should be upper case (space, dash, apostrophe, etc).

    a!localVariables(
      local!chars: {"'"," ","-"}, /* Any leading char that determins upper next */
      local!capIndex: reject(
        fn!isnull,
        a!forEach(
          items: 1+enumerate(len(ri!string)),
          expression: if(
            or(
              fv!isFirst,
              contains(local!chars,charat(ri!string,fv!index))
            ),
            if(fv!isFirst,1,fv!index+1),
            null
          )
        )
      ),
      
      concat(
        a!forEach(
          items: 1+enumerate(len(ri!string)),
          expression: if(
            contains(local!capIndex,fv!index),
            upper(charat(ri!string,fv!index)),
            charat(ri!string,fv!index)
          )
        )
      )
    )