Solved

Search for a String within a String

Posted on 2014-02-03
3
359 Views
Last Modified: 2014-02-15
How can I search a string for another string?
For example I have a path = "C:\directory\test\directory\directory..."

I want to know if it is pointed to the "TEST" directory so I want to search for the word TEST that may or may not always be in the same place everytime...therefore I don't want to say look for the word test in position 3 for a length of 4 like SUBSTR...but rather look for the word TEST any where within that string and do something...

How can I look for the entire word test within another string (path)?

Thanks,
Mark
0
Comment
Question by:smithmrk
3 Comments
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
ID: 39829974
It is easy - FoxPro offers substring test operator:

path = "C:\directory\test\directory\directory..."
IF "\test\" $ LOWER(path)
  *-- Test subfolder found
ENDIF

Other related functions are:
AT(), ATC(), OCCURS(), etc. Alternatives used for double byte characters are also available.

To replace a part of string by some other text look for:
STRTRAN(), CHRTRAN(), STREXTRACT(), STUFF(), etc.
0
 

Author Closing Comment

by:smithmrk
ID: 39830002
Thanks!
0
 

Expert Comment

by:HarrowdenIT
ID: 39861828
There's a couple of ways you can do this.

1. IF "TEST"$UPPER(lcFilePath) ....

or

2. IF AT("TEST",UPPER(lcFilePath))>0 ...

Hope this helps.

Regards
Gary
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

912 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now