Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i delimit inside a field

Status
Not open for further replies.

borsker

Programmer
Jul 24, 2002
147
0
0
US
I have one name field that has "first, last" in it. Is there anyway i can delimit this one field into two fields with the delimiter ",".
 
no, i am talking about a dbf that has a field called name. it is populated with people's names. (ex: Doe, John)
i want to delimit this field into two fields. (ex first field will have John in it and last field will have Doe in it.)

I might not be explaining this right.
--- original file
name
Doe, John
Doe, Jane

--- altered file with 2 new fields
name first last
Doe,John John Doe
Doe,Jane Jane Doe
 
Code:
REPLACE ALL First WITH DlimitField(Name,1),;
            Last  WITH DlimitField(Name,2)

FUNCTION DlimitField(lcName,lnCounter)
  LOCAL lnFlds, laFlds[1]
  LOCAL lcRetVal
  lnFlds = ALINES(laFlds,lcName,1+2,[,])
  IF m.lnFlds < m.lnCounter
     lcRetVal = []
  ELSE
     lcRetVal = laFlds[m.lnCounter]
  ENDIF

RETURN m.lcRetVal
(Not tested)

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 

borsker,

A similar problem appeared here a number of times, as far as I can remeber.

A quick search on keywords "field name first last" returned results out of which I selected these:

thread184-1229461
thread184-739568
faq184-4326

I am sure there are more, if you put more time into the search.
 
Borsker
Code:
[COLOR=blue]REPL TABLENAME.firstname WITH LEFT(TABLENAME.fieldname,AT([,],TABLENAME.fieldname) - 1),;
[tab]TABLENAME.lastname WITH SUBSTR(TABLENAME.fieldname,AT([,],TABLENAME.fieldname) + 1);
[tab]ALL IN TABLENAME[/color]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander.com
PDFcommander.co.uk
 

Oops, wrong way round!
Code:
[COLOR=blue]REPL TABLENAME.lastname WITH LEFT(TABLENAME.fieldname,AT([,],TABLENAME.fieldname) - 1),;
    TABLENAME.firstname WITH SUBSTR(TABLENAME.fieldname,AT([,],TABLENAME.fieldname) + 1);
    ALL IN TABLENAME[/color]

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander.com
PDFcommander.co.uk
 
If you're in VFP 7 or later, you can use STREXTRACT() to cut the code way down:

REPLACE LastName WITH STREXTRACT(Name, "", ","), ;
FirstName WITH ALLTRIM(STREXTRACT(Name, ",")) ;
IN YourTable

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top