Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 938
  • Last Modified:

VFP 9 How To Parse Char String?

Hi all. I would like to be able to pull three words greater in length than 6 chars from a text string.

When parsing the string what I need is for the first word encountered where LEN => 6 to populate a form text field, then continue parsing the string, so that the second word matching populates a second form text field, and so on for a total of three text fields populated.

The object is to try and extract somewhat important keywords, while eliminating more common words, hence the 6 char minimum.

I don't know how to perform such a search on a string, so I'm hoping someone here can help me out. Thx!
0
formadmirer
Asked:
formadmirer
  • 2
1 Solution
 
z_alexCommented:
please give example.

Or you mean by using  substring or substr()
0
 
pcelbaCommented:
Following procedure returns three words as output parameters. Calling sample:

lcText = "I don't know how to perform such a search on a string, so I'm hoping someone here can help me out."

STORE "" TO lcW1, lcW2, lcW3

DO l_getThreeWords WITH lcText, lcW1, lcW2, lcW3

... and now you may assign values from variables lcW1, lcW2, lcW3 to your form text fields.
PROCEDURE l_getThreeWords
LAPARMETERS lcText, lcWord1, lcWord2, lcWord3

LOCAL lnI, lnW, lcWord
lnW = 0

STORE '' TO lcWord1, lcWord2, lcWord3

FOR lnI = 1 TO GETWORDCOUNT(lcText)
  
  lcWord = GETWORDNUM(lcText, lnI)
  IF LEN(lcWord) > 6
    lnW = lnW + 1
    STORE lcWord TO ('lcWord' + ALLTRIM(STR(lnW)))
    IF lnW = 3
      RETURN
    ENDIF
  ENDIF
  
NEXT

RETURN

Open in new window

0
 
formadmirerAuthor Commented:
Absolutely amazing! Super fast response with a solution that works perfectly for what I need.
Thank you so much!
0
 
pcelbaCommented:
You are welcome!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now