Fox 9  searching string

Malibucompany used Ask the Experts™
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


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

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
More elegant could be Regular expression test but it is also very slow and not necessary in this case.

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

Olaf DoschkeSoftware Developer
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 ;

   * Correct string.

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

Bye, Olaf.
Where is the test for digits required in the spec?  :-)
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Olaf DoschkeSoftware Developer
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.
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.
Olaf DoschkeSoftware Developer
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.


Perfect !

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial