3

I have a column of strings separated by comma.

Example: City, Zipcode

I want to make a column with only city populated so everything before the comma.

How has anyone else accomplished this? I know with Foxpro you can usually accomplish the same task various ways. Any help would be appreciated.

EDIT: SOLUTION

GETWORDNUM(FIELD,1,",")

This worked to give the text string before the comma from the column FIELD.

Govind Parmar
  • 20,656
  • 7
  • 53
  • 85

3 Answers3

4

The easiest way to do that is to use STREXTRACT(). ie:

lcColumnData = "City, Zipcode"

? STREXTRACT(m.lcColumnData, "",",")
Cetin Basoz
  • 22,495
  • 3
  • 31
  • 39
2
STORE ALINES(aCZ, "Atlanta, 30301", ",") TO iCZ

City = aCZ[1]
ZipCode = aCZ[2]

?City
?ZipCode
Keht
  • 57
  • 9
0

Try this:

str = "City, Zipcode"

*initialize the column value leftcol
leftcol = ''   
*find comma position
pos = At(',', str)
Do Case
  Case pos > 1 
    * there is a comma and something before that. take everything before that pos
    leftcol = Left(str, pos-1)

  Case pos = 1
    * first char is comma
    leftcol = ''

  Otherwise
    *there is no comma. take the whole string
    leftcol = str
EndCase
Polymath
  • 630
  • 7
  • 11
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 20 '21 at 07:40