Solved

Fox 9  searching string

Posted on 2011-09-06
7
242 Views
Last Modified: 2012-05-12
I am writing some code which will require me to validate a character string.
Two things need to be done.
1) Verify the number of charatcers in a string
2) Verify that a certain position is a letter rather than a number

example:
12345x7890

Verifiy that there are ten characters in the string and that the 6th one is a letter rather than a number.

I can do this  with the Substr(str,x,y) etc   function  just wondered if anyone knew of a more elegant way .

Thank You
D


0
Comment
Question by:Malibucompany
[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
  • 3
  • 3
7 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 250 total points
ID: 36491216
More elegant could be Regular expression test but it is also very slow and not necessary in this case.
See http://www.sweetpotatosoftware.com/SPSBlog/PermaLink,guid,91241006-595a-487d-ac06-d0fc1fc71632.aspx
http://fox.wikis.com/wc.dll?Wiki~RegExp

The old and good SUBSTR() is also fast, readable, and fully functional.

lcStr = "12345x7890"
IF LEN(lcStr) = 10 AND ISALPHA(SUBSTR(lcStr, 6, 1))
  *-- Correct string
ENDIF

0
 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 250 total points
ID: 36491618
Also see IsDigit() for checking the other 9 chars are digits. Or do

lcStr = "12345x7890"
lnExpectedLength = 10
lnCheckPositionOfAlpha = 6

lcChr = ChrTran(lcStr,"0123456789","")
If IsAlpha(lcChr) AND;
   Len(lcStr)=lnExpectedLength AND ;
   Substr(lcStr,lnCheckPositionOfAlpha,1)==lcChr

   * Correct string.
Endif

This is lengthier code, but it also checks all but the one alphabetical char are digits.

Bye, Olaf.
0
 
LVL 42

Assisted Solution

by:pcelba
pcelba earned 250 total points
ID: 36491690
Where is the test for digits required in the spec?  :-)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 250 total points
ID: 36491875
chrtran() is removing all digits, and digits only. Also substr(...,1)==lcChar checks the single char substr with the string remaining from chrtran,The == exact string match is therefore checking this is only 1 and exactly 1 alphabetical char.

Test for yourself.

Bye, Olaf.
0
 
LVL 42

Assisted Solution

by:pcelba
pcelba earned 250 total points
ID: 36491995
Olaf, I understand your code... but thanks for the explanation.

I am just asking Where is the test for digits required in the specification from Malibucompany?  :-)

The question just says "Letter on the 6th place rather than digit" but no info about other string positions exists.
0
 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 250 total points
ID: 36501572
Well, I interpret that all other non alphabetical chars should be digits. That was not explicitly demanded, but it's an implicit interpretation, that follows quite obviously. Malibucompany could clarify that of course.

Bye, Olaf.
0
 

Author Closing Comment

by:Malibucompany
ID: 37024824
Perfect !
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Part One of the two-part Q&A series with MalwareTech.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

617 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