0

Initials

How can I get every first letter in each word in a field, for example, initial a name?

Let say the name, John F Kennedy, I want it JFK.

Thanks.

5replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hi Jan

     

    How about

     

    let w := "John F Kennedy";
    let i := ""
    for a in split(w," ") do
    i := i + substring(a,0,1)
    end;
    i

     

    Regards John

    Like
  • This kind of problem can also be solved with a regular expression ("Text" is the name of the source field):

    replacex(Text + " ", "(\S)\S*\s+", "g", "$1")

    Like
  • Thanks Alain

     

    I must have soent an hour trying to do that and could not for the life of me get to grips with it. Could you explain the regex expression and what the g and $1 are. I'd really appreciate it

     

    Regards John

    Like
  • The expression matches a suite consisting of:

    (\S) : a single non-space ; put in parentheses so it is memorized if found ;

    \S* : zero or more non-spaces ;

    \s+ : one or more spaces or equivalent.

    If a match is found, the suite is replaced by the content of the first (in this case only) captured value : $1.

    And the process is repeated as long as further matches can be found, as instructed by the "g" (global) flag.

    Like
  • Thanks Alain. I would never have worked that out. Time to learn a bit about Regex...

    Like
Like Follow
  • 1 yr agoLast active
  • 5Replies
  • 222Views