Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parse Name into separate fields function
Message
From
05/09/2008 09:36:10
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01345118
Message ID:
01345130
Views:
23
This message has been marked as the solution to the initial question of the thread.
Hi Kirk,

in case of suffix len is max. 2 and initial len is max 1 this could do:


DIMENSION arr1(3)
arr1(1) = [Kelly Jr Kirk A]
arr1(2) = [Smith Bob]
arr1(3) = [Roberts Ben D]

CLEAR
FOR i = 1 TO ALEN(arr1,1)

IF GETWORDCOUNT(arr1(i),[ ]) > 2

IF LEN(GETWORDNUM(arr1(i),GETWORDCOUNT(arr1(i),[ ]))) = 1
? GETWORDNUM(arr1(i),GETWORDCOUNT(arr1(i),[ ]) - 1,[ ]) + [ ]
?? GETWORDNUM(arr1(i),GETWORDCOUNT(arr1(i),[ ]),[ ]) + [. ]
ELSE
? GETWORDNUM(arr1(i),GETWORDCOUNT(arr1(i),[ ]),[ ]) + [ ]
ENDIF

?? GETWORDNUM(arr1(i),1,[ ]) + [ ]

IF LEN(GETWORDNUM(arr1(i),2,[ ])) <= 2
?? GETWORDNUM(arr1(i),2,[ ])
ENDIF

ELSE

? GETWORDNUM(arr1(i),2,[ ]) + [ ]
?? GETWORDNUM(arr1(i),1,[ ])

ENDIF

ENDFOR


However, you should have a look at regular expressions. Those are much more powerful....

>Does anyone have a routine written that they could share to parse a name field into the separate fields.
>
>I have to import a file, and the name is all in one field, the current value of the field is formatted as:
>
>lastname suffix firstname midle-initial
>
>Example
>Kelly Jr Kirk A
>Smith Bob
>Roberts Ben D
>
>
>Thanks for any help.
>
>Kirk
Best Regards
-Tom

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it.

Oh, and BTW: 010101100100011001010000011110000101001001101111011000110110101101110011
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform