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.

5 replies

null
    • John_Halls
    • 2 yrs ago
    • Reported - view

    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

    • Alain_Fontaine
    • 2 yrs ago
    • Reported - view

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

    • John_Halls
    • 2 yrs ago
    • Reported - view

    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

    • Alain_Fontaine
    • 2 yrs ago
    • Reported - view

    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.

    • John_Halls
    • 2 yrs ago
    • Reported - view

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

Content aside

  • 2 yrs agoLast active
  • 5Replies
  • 264Views