Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for a Number in a text string 5

Status
Not open for further replies.

tjc240e

Technical User
Nov 12, 2004
133
US
Is there an easy way to search a text string for the occurance or any number?

If i have "CUSICK #118-92-2202", All i would need is for the function to return a true because a number exists in the string.

Suggestions?
 
Hi

cString = "abcdefskdjkj-3sd"

i=0
lFound = .f.
DO WHILE i < 10
IF ALLTRIM(STR(i)) $ cString
lFound = .t.
EXIT
ENDIF
i=i+1
ENDDO

IF lFound
=MESSAGEBOX("Digits found")
ELSE
=MESSAGEBOX("No Digits found")
ENDIF


____________________________________________
ramani - (Subramanian.G) :)
 
Oh.. I am too slow in my keyboard, I think. When I startted, no reply and when I ended, this is 3rd reply and this the 4th message, I hope. ! :)

____________________________________________
ramani - (Subramanian.G) :)
 
is the $ in the "IF ALLTRIM(STR(i)) $ cString" statement mean contains?
 
How about:
Code:
?LEN(cstring)=LEN(CHRTRAN(cstring,"1234567890",""))
Regards,

Mike
 
mspratt,
could you tell me what that statement is doing?
I understand ? (Display to screen)
LEN(cstring)=Length of cstring)
but I don't understand CHRTRAN and why is it LEN(...)??

Thanks for the clarifications...
 
Hi,

Code:
Set library to foxtools && once in startup code
? NOT (Strfilter(cExpression,"0123456789")=="")

Bye, Olaf.
 
tjc240e,

Here is what it does:

cstring="CUSICK #118-92-2202"
IF LEN(cstring)=LEN(CHRTRAN(cstring,"1234567890",""))
=MESSAGEBOX("No Digits found")
ELSE
=MESSAGEBOX("Digits found")
ENDIF

CHRTRAN() is a function that substitutes characters in a character string. In this case, CHRTRAN will try to remove each digit in a string (replace it by empty string ""). If the length of the string didn't change after that, there were no digits to start with.

 
AHHHH... (the light bulb clicks on dimly)
Thanks, now i see more clearly.

Thanks a lot.
 
Oh, and Olaf's solution does a similar thing the other way around. StrFilter() is a FoxTools function that removes characters from a string except those specified. So if you remove all except digits, and the string is not empty after that, then it means that you do have digits in your string. Makes sense?
 
Yes. Thank you. There is going to be a new thread started as soon as I get my thoughts together so keep by your keyboards...

Thanks about 10 million!!!!!
 
Sorry I was not as clear as I should have been. I thought the code spoke for itself.

You wrote you wanted .t. or .f. for if there was a number in the string. Check into STRTRAN() as well.

Regards,

Mike
 
Not a problem mspratt... i'm still new to this foxpro stuff and unfortunately we don't have a really good reference guide and are still using version 6.

Also I just got thrown into this becuase i know a bit about programming, so i am picking it up but it's have without manuals/user guides or in house help... that is why I am soo thankful for all of you out there and all you do to help.

TJC
 
tjc240e,

Help files are really of a great help, so don't disregard it. (Oh, and we still use VFP6 as well.)

If, for some reason, you don't have Help (I don't think, though, they should throw you into a new language without providing at least that help that comes free with the package), you can always find free reference on MSDN site, . Even though you can find full documentation there only for versions 7 and up, it would still be useful. Say, you could have looked up CHRTRAN() function to understand what it does.

Besides Microsoft itself, you can also find other free online resources. Say, this VFP6 tutorial:
Stella
 
Hi,

VFP Help on VFP6 is available if you don't only installed VFP (and other parts of the Visual Studio 6), but also MSDN. And then you can also choose to search only in VFP6 help, not the whole MSDN. Otherwise it's sometimes harder to find something VFP specific.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top