Solved

VFP 9 How To Parse Char String?

Posted on 2010-09-10
4
913 Views
Last Modified: 2012-05-10
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
Comment
Question by:formadmirer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Expert Comment

by:z_alex
ID: 33650440
please give example.

Or you mean by using  substring or substr()
0
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 33650466
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
 

Author Closing Comment

by:formadmirer
ID: 33650567
Absolutely amazing! Super fast response with a solution that works perfectly for what I need.
Thank you so much!
0
 
LVL 42

Expert Comment

by:pcelba
ID: 33650926
You are welcome!
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question