Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

What CF tags do I use ? - still cannot get it to work

New Here ,
Nov 10, 2009 Nov 10, 2009

I think I saw this post somewhere but I cannot find it. I tried myself and got it partially to work but not entirely.

I have a name, like Joe Smith, and I need to output it to J. Smith. I think I can do that. But where I have problem is if the the name is Joe C Smith (no period after the middle C). I need to convert that to J.C. Smith, or J. C. Smith. My current technique makes it J. C Smith (no period after the middle C).

What coldfusion functions would I use to convert Joe C Smith to J.C. Smith, or what sql commands, if that is a better approach.

TOPICS
Getting started
736
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 10, 2009 Nov 10, 2009

You could use list functions to remove the last element of a space-delimited list to be the surname, and then treat the remainder as a list of forenames loop over them, truncating them.

You could probably use a regex replace to do it also, but I haven't had coffee yet so am not going to tackle that one.

One note though.  What about names that don't follow the pattern "forename[ forename[...]] surname", like a lot of non-european names do?  Some name patterns have the family name first, and the given names second.

To be honest, I would not monkey with people's names, I'd just leave them as the way they chose to type them in.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 10, 2009 Nov 10, 2009

You would probably have some luck using the list functions and treating your name as a space delimited list.

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_13.html

<cfouput>#listLen("Joe C Smith"," ")#</cfoutput>

But I do wonder how you plan to account for my favorite name "Mary Joe Sue Von der LongName".  An unusual name from a mix of cultures, but it does demonstrate that all names are not three single words for first, middle and last.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 12, 2009 Nov 12, 2009
I do wonder how you plan to account for my favorite name "Mary Joe Sue Von der LongName".

We in The Netherlands would say M.J.S. van de LangeNaam, or just plain Mary Joe. The surname isn't just LangeNaam, but van de LangeNaam.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 12, 2009 Nov 12, 2009

BKBK wrote:

I do wonder how you plan to account for my favorite name "Mary Joe Sue Von der LongName".

We in The Netherlands would say M.J.S. van de LangeNaam, or just plain Mary Joe. The surname isn't just LangeNaam, but van de LangeNaam.

Exactly why I love this example.  There may not be many southern U.S. expatriates living in The Netherlands and|or Dutch emigrants to the U.S,. south that have chosen to mix name traditions in such a manner.  But with 6+ Billion people in the world, there maybe at least one or two such people.

And if her name is in ones databases I just hope she is not upset when ones system names her M.J.S.V.D. Longname.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2009 Nov 15, 2009

To turn to New York Guy's original question, you could put the required functionality in a function, like this:

<cfscript>
function convertToInitials(fullName) {
    // array to store name initials
    var initial = arrayNew(1);
    var convertedName = "";
    var currentName = "";
    var isCurrentNameInitial = false;
    var surname = listlast(fullname," ");
    var numberOfNameElements = listLen(fullName," ");
    // initialize array
    var arrayIsSet = arraySet(initial, 1,numberOfNameElements, "");
    var i = 1;
    if (numberOfNameElements GT 1) {
        for (i=1; i LT numberOfNameElements; i=i+1) {
            // i-th name
            currentName = listGetAt(fullName,i," ");
            // Test whether current name already an initial of the form A., A.B., A.B.C., etc?
            isCurrentNameInitial = REfindNoCase("([a-z]\.)+$",currentName,1,false) GT 0;           
            if (isCurrentNameInitial) {
                initial = currentName;
                convertedName = convertedName & initial;
            }
            else {
                // get uppercased initial letter of i-th name
                initial = ucase(left(currentName,1));
                convertedName = convertedName & initial & ".";
            }
        }
    }
    convertedName = convertedName & " " & surname;
    return convertedName;
}
</cfscript>

<!--- Test the func! --->

The New York Guy: <cfoutput>#convertToInitials("The New York Guy")#</cfoutput><br>

A.K.A. The New York Guy: <cfoutput>#convertToInitials("A.K.A. The New York Guy")#</cfoutput>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 17, 2009 Nov 17, 2009

As per Ian's earlier post, that sort of function's not much chop if your name is Leonardo da Vinci or Vincent van Gogh or similar.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 17, 2009 Nov 17, 2009
As per Ian's earlier post, that sort of function's not much chop if your name is Leonardo da Vinci or Vincent van Gogh or similar.

Per Ian's post, it actually is! Look at his M.J.S.V.D. Longname. Hence, Signor L.D. Vinci and De Heer V.V. Gogh. It was actually my earlier post that pointed out that van de LangeNaam  is a single name in The Netherlands. Hence, V. van Gogh, not V.V. Gogh.

However, we're in the English-speaking world. The function is an answer to New York Guy's original question.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 17, 2009 Nov 17, 2009

BKBK wrote:

As per Ian's earlier post, that sort of function's not much chop if your name is Leonardo da Vinci or Vincent van Gogh or similar.

Per Ian's post, it actually is! Look at his M.J.S.V.D. Longname. Hence, Signor L.D. Vinci and De Heer V.V. Gogh. It was actually my earlier post that pointed out that van de LangeNaam  is a single name in The Netherlands. Hence, V. van Gogh, not V.V. Gogh.

However, we're in the English-speaking world. The function is an answer to New York Guy's original question.

I think what Adam, I, and I beleive you are pointing out is that this is a fairly trivial technical task to modify a name in such a manner and your function would clearly do that.

But we are also pointing out it is likely a mistake to think that all names, even in our English-speaking world, follow such a simply rule as "First Middle Last".  There are many compound first, middle and especially last names.  If you look at a data set of names that is even a moderate size you are probably going to find at least a few examples of this.

If your system is storing names as a single string, one is going to have a very dificult time correctly parsing such strings into sub strings without human intervention.  And even then, the only way to be sure of correctly identifying the parts of all names is to ask the name holders.

Message was edited by: ianskinner The very fist result of this search seems to indicate that it is easy to find real examples of such a name problem in the very English American city of Sacramento California. http://www.whitepages.com/search/Replay?lower=1&search_id=80171450726281793213&search_type=findperson_advanced Pamela Von Behren Merritt

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 17, 2009 Nov 17, 2009

Indeed, Ian. It is more than a difficult problem. It can easily be shown there are potentially an infinite number of rules for creating initials from names in any language! Luckily, New York Guy's question narrows the field a bit:

I have a name, like Joe Smith, and I need to output it to J. Smith. I think I can do that. But where I have problem is if the the name is Joe C Smith (no period after the middle C). I need to convert that to J.C. Smith, or J. C. Smith...

What coldfusion functions would I use to convert Joe C Smith to J.C. Smith...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 17, 2009 Nov 17, 2009
LATEST

Well I dunno about where you come from, but where I come from, the conventions people use to express their names - even if they are foreign names - do not change just because they're in a country that has English as its primary language.

When the Springboks visit New Zealand, Heinke van der Merwe doesn't change from being H. van der Merwe to being H.V.D. Merwe.http://en.wikipedia.org/w/index.php?title=Heinke_van_der_Merwe&action=edit&redlink=1

Is that your experience?

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources