Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Name parcer???
Message
De
06/04/2013 02:46:21
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01570274
Message ID:
01570276
Vues:
74
>I have a bunch of data that has people's name all squeezed into one field like
>Smith, John, D Jr
>
>..and I need to of course put it in 3 fields (first name, middle name, last name) - anyone got anything like that?

Off-the-cuff code here (untested):
* * Assumes pattern of  "Last, First, Middle" - assumes comma is delimiter and there are
*   no more than three items (otherwise last item contains remainder which may contain
*   commas).
* * Really bad form here -- as it is a UDF that doesn't return a meaningful value, and
*   modifies values of some of its parameters.
* * Somewhat "brute force" method -- probably not the best way to handle this.
STORE "" TO cLN,cFN,cMN
=ParseName( "Smith, John, D Jr", @cLN, @cFN, @cMN )
? "Last: ",m.cLN
? "First: ",m.cFN
? "Middle: ",m.cMN

PROCEDURE ParseName ( cFullName, cLast, cFirst, cMiddle )
    LOCAL nLoc

    nLoc = AT(",",m.cFullName)
    cFirst = ""
    cMiddle = ""
    IF m.nLoc==0 THEN
        cLast = ALLTRIM(m.cFullName)
    ELSE
        cLast = ALLTRIM(SUBSTR(m.cFullName,1,m.nLoc-1))
        cFirst = ALLTRIM(SUBSTR(m.cFullName,m.nLoc+1)
        nLoc = AT(",",m.cFirst)
        IF m.nLoc<>0 THEN
            cMiddle = ALLTRIM(m.cFirst,m.nLoc+1)
            cFirst = ALLTRIM(m.cFirst,1,m.nLoc-1)
        ENDIF
    ENDIF
ENDPROC
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform